#include "class_center.h"

//实现行情类
class_center::class_md_spi::class_md_spi(class_center *p)
{
center_p = p;
}

class_center::class_md_spi::~class_md_spi()
{
}

///当客户端与交易后台建立起通信连接时（还未登录前），该方法被调用。
void class_center::class_md_spi::OnFrontConnected()
{
center_p->flag[5] = 1;
std::cout << "行情前置机连接成功\n";
center_p->log.insert("log", "行情前置机连接成功");
}

///当客户端与交易后台通信连接断开时，该方法被调用。当发生这个情况后，API会自动重新连接，客户端可不做处理。
///@param nReason 错误原因
///        0x1001 网络读失败
///        0x1002 网络写失败
///        0x2001 接收心跳超时
///        0x2002 发送心跳失败
///        0x2003 收到错误报文
void class_center::class_md_spi::OnFrontDisconnected(int nReason)
{
for (size_t i = 5; i < 25; i++)
{
center_p->flag[i] = 0;
}
std::cout << "行情前置机中断" << nReason << std::endl;
center_p->log.insert("log", "行情前置机连接中断"+std::to_string(nReason));
}

///心跳超时警告。当长时间未收到报文时，该方法被调用。
///@param nTimeLapse 距离上次接收报文的时间
void class_center::class_md_spi::OnHeartBeatWarning(int nTimeLapse)
{
	std::cout<<"心跳超时"<<nTimeLapse<<std::endl;
center_p->log.insert("log","心跳超时"+std::to_string(nTimeLapse));
}


///登录请求响应
void class_center::class_md_spi::OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
if (pRspInfo != nullptr && pRspInfo->ErrorID == 0)
{
center_p->flag[6] = 1;
std::cout << "行情登录成功" << std::endl;
center_p->log.insert("log", "行情登陆成功");
}
}

///登出请求响应
void class_center::class_md_spi::OnRspUserLogout(CThostFtdcUserLogoutField* pUserLogout, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
center_p->flag[6] = 0;
}

///错误应答
void class_center::class_md_spi::OnRspError(CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
	std::stringstream xx;
if(pRspInfo !=nullptr)
{
xx<<"信息正文:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"消息ID:"<<pRspInfo->ErrorID;
}
std::cout << "行情错误应答" << xx.str()<< std::endl;
center_p->log.insert("行情错误应答", xx.str());
}

///订阅行情应答
void class_center::class_md_spi::OnRspSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
if (bIsLast == true)
{
center_p->flag[11] = 1;
}
center_p->flag[12]++;
center_p->log.insert("订阅行情应答",pSpecificInstrument->InstrumentID);
}

///取消订阅行情应答
void class_center::class_md_spi::OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{}

///订阅询价应答
void class_center::class_md_spi::OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{}

///取消订阅询价应答
void class_center::class_md_spi::OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{}

///深度行情通知
void class_center::class_md_spi::OnRtnDepthMarketData(CThostFtdcDepthMarketDataField* pDepthMarketData)
{
if (pDepthMarketData == nullptr) { return; }
if (center_p->flag[2] == 1 && center_p->flag[0] == 1)
{
center_p->tick_map[pDepthMarketData->InstrumentID] = *pDepthMarketData;

//屏蔽交易状态
//std::string str00 = pDepthMarketData->InstrumentID;
if(center_p->tick_status_map.find(pDepthMarketData->InstrumentID) != center_p->tick_status_map.end() && center_p->tick_status_map[pDepthMarketData->InstrumentID] != '2')
{
return;
}

//插入BAR
center_p->bars_map[pDepthMarketData->InstrumentID].insert(*pDepthMarketData);
//插入tick
center_p->ticks_map[pDepthMarketData->InstrumentID].insert(*pDepthMarketData);
//脉冲
if(center_p->tick_event_map.find(pDepthMarketData->InstrumentID) != center_p->tick_event_map.end())
{
center_p->tick_event_map[pDepthMarketData->InstrumentID].notify();
}
}
}


///询价通知
void class_center::class_md_spi::OnRtnForQuoteRsp(CThostFtdcForQuoteRspField* pForQuoteRsp)
{}

//实现行情类结束


//实现交易类开始
class_center::class_trader_spi::class_trader_spi(class_center* p)
{
center_p = p;
}

class_center::class_trader_spi::~class_trader_spi() 
{
}

///当客户端与交易后台建立起通信连接时（还未登录前），该方法被调用。
void class_center::class_trader_spi::OnFrontConnected()
{
center_p->flag[25] = 1;
std::cout << "交易前置机连接成功" << std::endl;
center_p->log.insert("log", "交易前置机连接成功");
}

///当客户端与交易后台通信连接断开时，该方法被调用。当发生这个情况后，API会自动重新连接，客户端可不做处理。
///@param nReason 错误原因
///        0x1001 网络读失败
///        0x1002 网络写失败
///        0x2001 接收心跳超时
///        0x2002 发送心跳失败
///        0x2003 收到错误报文
void class_center::class_trader_spi::OnFrontDisconnected(int nReason) 
{
for (int i = 25; i < 50; i++)
{
center_p->flag[i] = 0;
}
std::cout << "交易前置机断开" << nReason << std::endl;
center_p->log.insert("log", "交易前置机断开" + std::to_string(nReason));
}

///心跳超时警告。当长时间未收到报文时，该方法被调用。
///@param nTimeLapse 距离上次接收报文的时间
void class_center::class_trader_spi::OnHeartBeatWarning(int nTimeLapse)
{
std::cout<<"交易心跳超时"<<nTimeLapse<<std::endl;
center_p->log.insert("log","交易心跳超时"+std::to_string(nTimeLapse));
}

///客户端认证响应
void class_center::class_trader_spi::OnRspAuthenticate(CThostFtdcRspAuthenticateField* pRspAuthenticateField, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
if (pRspInfo != nullptr &&pRspInfo->ErrorID == 0)
{
center_p->flag[29] = 1;
center_p->log.insert("log", "认证成功");
std::cout << "认证成功" << std::endl;
}
}


///登录请求响应
void class_center::class_trader_spi::OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
if (pRspInfo != nullptr && pRspInfo->ErrorID == 0)
{
center_p->tradingday = pRspUserLogin->TradingDay;
center_p->frontid = pRspUserLogin->FrontID;
center_p->sessionid = pRspUserLogin->SessionID;
center_p->orderref = atoi(pRspUserLogin->MaxOrderRef);
//center_p->position_map.clear();
for(auto &pair: center_p->position_map)
{
	memset(&pair.second.p22, 0, sizeof(CThostFtdcInvestorPositionField) );
	memset(&pair.second.p23, 0, sizeof(CThostFtdcInvestorPositionField) );
	memset(&pair.second.p12, 0, sizeof(CThostFtdcInvestorPositionField) );
	memset(&pair.second.p13, 0, sizeof(CThostFtdcInvestorPositionField) );
}
center_p->hy_map.clear();
//交易状态通知内容
center_p->instrument_status_map.clear();
//行情交易状态
center_p->tick_status_map.clear();
//报单录入请求响应map
center_p->InputOrder_map.clear();
//清空结算单
center_p->SettlementInfo_str="";

center_p->flag[26] = 1;
std::stringstream xx;
xx<<"交易登录成功\n交易日"
<<pRspUserLogin->TradingDay
<<"登录成功时间"
<<pRspUserLogin->LoginTime
<<"经纪公司代码"
<<pRspUserLogin->BrokerID
<<"用户代码"
<<pRspUserLogin->UserID
<<"交易系统名称"
<<pRspUserLogin->SystemName
<<"前置编号"
<<pRspUserLogin->FrontID
<<"会话编号"
<<pRspUserLogin->SessionID
<<"最大报单引用"
<<pRspUserLogin->MaxOrderRef
<<"上期所时间"
<<pRspUserLogin->SHFETime
<<"大商所时间"
<<pRspUserLogin->DCETime
<<"郑商所时间"
<<pRspUserLogin->CZCETime
<<"中金所时间"
<<pRspUserLogin->FFEXTime
<<"能源中心时间"
<<pRspUserLogin->INETime
<<"后台版本信息"
<<pRspUserLogin->SysVersion
<<"广期所时间"
<<pRspUserLogin->GFEXTime
<<"当前登录中心号"
<<pRspUserLogin->LoginDRIdentityID
<<"用户所属中心号"
<<pRspUserLogin->UserDRIdentityID;
center_p->log.insert("log", xx.str());
std::cout << "交易登录成功" << std::endl;
}
if (pRspInfo != nullptr && pRspInfo->ErrorID == 64)//未认证
{
CThostFtdcReqAuthenticateField pReqAuthenticateField;//客户端认证结构体
memset(&pReqAuthenticateField, 0, sizeof(CThostFtdcReqAuthenticateField));
strcpy(pReqAuthenticateField.BrokerID, center_p->broker_str.c_str());
strcpy(pReqAuthenticateField.UserID, center_p->user_str.c_str());
strcpy(pReqAuthenticateField.AppID, center_p->userproductinfo_str.c_str());
strcpy(pReqAuthenticateField.AuthCode, center_p->authcode_str.c_str());
center_p->trader_api_p->ReqAuthenticate(&pReqAuthenticateField, ++center_p->nrequestid);
center_p->log.insert("log", "认证");
}

if(pRspInfo != nullptr && pRspInfo->ErrorID == 140)
{
//用户口令更新请求
CThostFtdcUserPasswordUpdateField UserPasswordUpdate;
memset(&UserPasswordUpdate, 0, sizeof(CThostFtdcUserPasswordUpdateField));
//经济公司代码
strncpy(UserPasswordUpdate.BrokerID, center_p->broker_str.c_str(), sizeof(UserPasswordUpdate.BrokerID));
//用户代码
strncpy(UserPasswordUpdate.UserID, center_p->user_str.c_str(), sizeof(UserPasswordUpdate.UserID));
//原来的口令
strncpy(UserPasswordUpdate.OldPassword, center_p->password_str.c_str(), sizeof(UserPasswordUpdate.OldPassword));
//新的口令
strncpy(UserPasswordUpdate.NewPassword, "huangzhen", sizeof(UserPasswordUpdate.NewPassword));

center_p->trader_api_p->ReqUserPasswordUpdate(&UserPasswordUpdate, ++center_p->nrequestid);
}

if (pRspInfo != nullptr)
{
	std::cout <<"登录请求响应"<<center_p->zm.zm(pRspInfo->ErrorMsg) << "错误ID：" << pRspInfo->ErrorID << std::endl;
}
}

///登出请求响应
void class_center::class_trader_spi::OnRspUserLogout(CThostFtdcUserLogoutField* pUserLogout, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
center_p->flag[26] = 0;
}

///用户口令更新请求响应
void class_center::class_trader_spi::OnRspUserPasswordUpdate(CThostFtdcUserPasswordUpdateField* pUserPasswordUpdate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
if(pUserPasswordUpdate != nullptr)
{
	std::cout<<"经纪公司代码"
		<<pUserPasswordUpdate->BrokerID
		<<"用户代码"
		<<pUserPasswordUpdate->UserID
		<<"原来的口令"
		<<pUserPasswordUpdate->OldPassword
		<<"新的口令"
		<<pUserPasswordUpdate->NewPassword<<std::endl;
}
if(pRspInfo != nullptr)
{
	std::cout<<"口令更新请求响应，错误id:"<<pRspInfo->ErrorID<<"，正文:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<std::endl;
}
}

///资金账户口令更新请求响应
void class_center::class_trader_spi::OnRspTradingAccountPasswordUpdate(CThostFtdcTradingAccountPasswordUpdateField* pTradingAccountPasswordUpdate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///报单录入请求响应
void class_center::class_trader_spi::OnRspOrderInsert(CThostFtdcInputOrderField* pInputOrder, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
 {
if(pRspInfo != nullptr)
{
center_p->InputOrder_map[nRequestID]=*pInputOrder;

std::stringstream str;
str<< "报单录入请求响应" <<center_p->zm.zm(pRspInfo->ErrorMsg)<<"id"<<pRspInfo->ErrorID<<std::endl;
str<<"经济公司代码"<<pInputOrder->BrokerID<<"合约代码"<<pInputOrder->InstrumentID<<"报单引用"<<pInputOrder->OrderRef<<"用户代码"<<pInputOrder->UserID<<"报单价格条件"<<pInputOrder->OrderPriceType<<"买卖方向"<<pInputOrder->Direction<<"组合开平标志"<<pInputOrder->CombOffsetFlag<<"组合投机套保标志"<<pInputOrder->CombHedgeFlag<<"价格"<<pInputOrder->LimitPrice<<"数量"<<pInputOrder->VolumeTotalOriginal<<"有效期类型"<<pInputOrder->TimeCondition<<"GTD日期"<<pInputOrder->GTDDate<<"成交量类型"<<pInputOrder->VolumeCondition<<"最小成交量"<<pInputOrder->MinVolume<<"触发条件"<<pInputOrder->ContingentCondition<<"止损价"<<pInputOrder->StopPrice<<"强平原因"<<pInputOrder->ForceCloseReason<<"自动挂起标志"<<pInputOrder->IsAutoSuspend<<"业务单元"<<pInputOrder->BusinessUnit<<"请求编号"<<pInputOrder->RequestID<<"用户强评标志"<<pInputOrder->UserForceClose<<"互换单标志"<<pInputOrder->IsSwapOrder<<"交易所代码"<<pInputOrder->ExchangeID<<"投资单元代码"<<pInputOrder->InvestUnitID<<"资金账号"<<pInputOrder->AccountID<<"币种代码"<<pInputOrder->CurrencyID<<"交易编码"<<pInputOrder->ClientID<<"IP地址"<<pInputOrder->IPAddress<<"Mac地址"<<pInputOrder->MacAddress;
center_p->log.insert("报单录入请求响应",str.str());
if(pRspInfo->ErrorID != 0)
{
	std::cout<<"报单录入错误id:"<<pRspInfo->ErrorID<<",正文:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<std::endl;
}
}
}

///预埋单录入请求响应
void class_center::class_trader_spi::OnRspParkedOrderInsert(CThostFtdcParkedOrderField* pParkedOrder, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///预埋撤单录入请求响应
void class_center::class_trader_spi::OnRspParkedOrderAction(CThostFtdcParkedOrderActionField* pParkedOrderAction, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///报单操作请求响应
void class_center::class_trader_spi::OnRspOrderAction(CThostFtdcInputOrderActionField* pInputOrderAction, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///查询最大报单数量响应
void class_center::class_trader_spi::OnRspQryMaxOrderVolume(CThostFtdcQryMaxOrderVolumeField* pQryMaxOrderVolume, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///投资者结算结果确认响应
void class_center::class_trader_spi::OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField* pSettlementInfoConfirm, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
	std::stringstream xx;
if (pRspInfo != nullptr && pRspInfo->ErrorID == 0)
{
center_p->flag[28] = 1;
}

if(pRspInfo != nullptr)
{
xx<<"消息正文:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"ID"<<pRspInfo->ErrorID<<std::endl;
}
if(pSettlementInfoConfirm != nullptr)
{
xx<<"经纪公司代码"<<pSettlementInfoConfirm->BrokerID<<"投资者代码"<<pSettlementInfoConfirm->InvestorID<<"确认日期"<<pSettlementInfoConfirm->ConfirmDate<<"确认时间"<<pSettlementInfoConfirm->ConfirmTime<<"结算编号"<<pSettlementInfoConfirm->SettlementID<<"投资者帐号"<<pSettlementInfoConfirm->AccountID<<"币种代码"<<pSettlementInfoConfirm->CurrencyID;
}
center_p->log.insert("投资者结算结果确认响应",xx.str());
}


///删除预埋单响应
void class_center::class_trader_spi::OnRspRemoveParkedOrder(CThostFtdcRemoveParkedOrderField* pRemoveParkedOrder, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///删除预埋撤单响应
void class_center::class_trader_spi::OnRspRemoveParkedOrderAction(CThostFtdcRemoveParkedOrderActionField* pRemoveParkedOrderAction, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///执行宣告录入请求响应
void class_center::class_trader_spi::OnRspExecOrderInsert(CThostFtdcInputExecOrderField* pInputExecOrder, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
	std::stringstream sem;
	if(pRspInfo != nullptr)
{
	sem<<"执行宣告录入请求响应"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"ID"<<pRspInfo->ErrorID<<std::endl;
}
if(pInputExecOrder != nullptr)
{
sem<<"经纪公司代码"<<pInputExecOrder->BrokerID
<<"投资者代码"<<pInputExecOrder->InvestorID
<<"执行宣告引用"<<pInputExecOrder->ExecOrderRef
<<"用户代码"<<pInputExecOrder->UserID
<<"数量"<<pInputExecOrder->Volume
<<"请求编号"<<pInputExecOrder->RequestID
<<"业务单元"<<pInputExecOrder->BusinessUnit
<<"开平标志"<<pInputExecOrder->OffsetFlag
<<"投机套保标志"<<pInputExecOrder->HedgeFlag
<<"执行类型"<<pInputExecOrder->ActionType
<<"保留头寸申请的持仓方向"<<pInputExecOrder->PosiDirection
<<"期权行权后生成的头寸是否自动平仓"<<pInputExecOrder->CloseFlag
<<"交易所代码"<<pInputExecOrder->ExchangeID
<<"投资单元代码"<<pInputExecOrder->InvestUnitID
<<"资金账号"<<pInputExecOrder->AccountID
<<"币种代码"<<pInputExecOrder->CurrencyID
<<"交易编码"<<pInputExecOrder->ClientID
<<"Mac地址"<<pInputExecOrder->MacAddress
<<"合约代码"<<pInputExecOrder->InstrumentID
<<"IP地址"<<pInputExecOrder->IPAddress<<std::endl;
}
//std::cout<<sem.str();
center_p->log.insert("执行宣告录入请求响应", sem.str() );
}


///执行宣告操作请求响应
void class_center::class_trader_spi::OnRspExecOrderAction(CThostFtdcInputExecOrderActionField* pInputExecOrderAction, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
	std::stringstream sem;
	if(pRspInfo != nullptr)
{
sem<<"执行宣告操作请求响应"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"ID"<<pRspInfo->ErrorID<<std::endl;
}
if(pInputExecOrderAction != nullptr)
{
	sem<<"经纪公司代码"<<pInputExecOrderAction->BrokerID
	<<"投资者代码"<<pInputExecOrderAction->InvestorID
	<<"执行宣告操作引用"<<pInputExecOrderAction->ExecOrderActionRef
	<<"执行宣告引用"<<pInputExecOrderAction->ExecOrderRef
	<<"请求编号"<<pInputExecOrderAction->RequestID
	<<"前置编号"<<pInputExecOrderAction->FrontID
	<<"会话编号"<<pInputExecOrderAction->SessionID
	<<"交易所代码"<<pInputExecOrderAction->ExchangeID
	<<"执行宣告操作编号"<<pInputExecOrderAction->ExecOrderSysID
	<<"操作标志"<<pInputExecOrderAction->ActionFlag
	<<"用户代码"<<pInputExecOrderAction->UserID
	<<"投资单元代码"<<pInputExecOrderAction->InvestUnitID
	<<"Mac地址"<<pInputExecOrderAction->MacAddress
	<<"合约代码"<<pInputExecOrderAction->InstrumentID
	<<"IP地址"<<pInputExecOrderAction->IPAddress<<std::endl;
}
std::cout<<sem.str();
center_p->log.insert("执行宣告操作请求响应", sem.str() );
}

///询价录入请求响应
void class_center::class_trader_spi::OnRspForQuoteInsert(CThostFtdcInputForQuoteField* pInputForQuote, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///报价录入请求响应
void class_center::class_trader_spi::OnRspQuoteInsert(CThostFtdcInputQuoteField* pInputQuote, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///报价操作请求响应
void class_center::class_trader_spi::OnRspQuoteAction(CThostFtdcInputQuoteActionField* pInputQuoteAction, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///批量报单操作请求响应
void class_center::class_trader_spi::OnRspBatchOrderAction(CThostFtdcInputBatchOrderActionField* pInputBatchOrderAction, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///期权自对冲录入请求响应
void class_center::class_trader_spi::OnRspOptionSelfCloseInsert(CThostFtdcInputOptionSelfCloseField* pInputOptionSelfClose, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
	std::stringstream sem;
	sem<<"期权自对冲录入请求响应"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"ID"<<pRspInfo->ErrorID<<std::endl;
sem<<"经纪公司代码"<<pInputOptionSelfClose->BrokerID<<"投资者代码"<<pInputOptionSelfClose->InvestorID<<"期权自对冲引用"<<pInputOptionSelfClose->OptionSelfCloseRef<<"用户代码"<<pInputOptionSelfClose->UserID<<"数量"<<pInputOptionSelfClose->Volume<<"请求编号"<<pInputOptionSelfClose->RequestID<<"业务单元"<<pInputOptionSelfClose->BusinessUnit<<"投机套保标志"<<pInputOptionSelfClose->HedgeFlag<<"期权行权的头寸是否自对冲"<<pInputOptionSelfClose->OptSelfCloseFlag<<"交易所代码"<<pInputOptionSelfClose->ExchangeID<<"投资单元代码"<<pInputOptionSelfClose->InvestUnitID<<"资金账号"<<pInputOptionSelfClose->AccountID<<"币种代码"<<pInputOptionSelfClose->CurrencyID<<"交易编码"<<pInputOptionSelfClose->ClientID<<"Mac地址"<<pInputOptionSelfClose->MacAddress<<"合约代码"<<pInputOptionSelfClose->InstrumentID<<"IP地址"<<pInputOptionSelfClose->IPAddress<<std::endl;
center_p->log.insert("期权自对冲录入请求响应",sem.str());
}

///期权自对冲操作请求响应
void class_center::class_trader_spi::OnRspOptionSelfCloseAction(CThostFtdcInputOptionSelfCloseActionField* pInputOptionSelfCloseAction, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///申请组合录入请求响应
void class_center::class_trader_spi::OnRspCombActionInsert(CThostFtdcInputCombActionField* pInputCombAction, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
if(pRspInfo != nullptr)
{
	std::cout<<"申请组合录入请求响应,信息:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"id:"<<pRspInfo->ErrorID<<std::endl;
}
if(pInputCombAction != nullptr)
{
	std::cout<<"经纪公司代码"
		<<pInputCombAction->BrokerID
		<<"投资者代码"
 	<<pInputCombAction->InvestorID
		<<"保留的无效字段"
		<<pInputCombAction->reserve1
		<<"组合引用"
		<<pInputCombAction->CombActionRef
		<<"用户代码"
 	<<pInputCombAction->UserID
		<<"买卖方向"
 	<<pInputCombAction->Direction
		<<"数量"
		<<pInputCombAction->Volume
		<<"组合指令方向"
 	<<pInputCombAction->CombDirection
		<<"投机套保标志"
		<<pInputCombAction->HedgeFlag
		<<"交易所代码"
		<<pInputCombAction->ExchangeID
		<<"保留的无效字段"
		<<pInputCombAction->reserve2
		<<"Mac地址"
		<<pInputCombAction->MacAddress
		<<"投资单元代码"
 	<<pInputCombAction->InvestUnitID
		<<"前置编号"
		<<pInputCombAction->FrontID
		<<"会话编号"
		<<pInputCombAction->SessionID
		<<"合约代码"
 	<<pInputCombAction->InstrumentID
		<<"IP地址"
		<<pInputCombAction->IPAddress
 	<<std::endl;
}
}


///请求查询报单响应
void class_center::class_trader_spi::OnRspQryOrder(CThostFtdcOrderField* pOrder, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询成交响应
void class_center::class_trader_spi::OnRspQryTrade(CThostFtdcTradeField* pTrade, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询投资者持仓响应
void class_center::class_trader_spi::OnRspQryInvestorPosition(CThostFtdcInvestorPositionField* pInvestorPosition, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
	if (pInvestorPosition != nullptr)
{
center_p->position_map[pInvestorPosition->InstrumentID].insert_position(*pInvestorPosition);
std::stringstream str;
str << "合约代码" << pInvestorPosition->InstrumentID << "经纪公司代码" << pInvestorPosition->BrokerID << "投资者代码" << pInvestorPosition->InvestorID << "持仓多空方向" << pInvestorPosition->PosiDirection << "投机套保标志" << pInvestorPosition->HedgeFlag << "持仓日期" << pInvestorPosition->PositionDate << "上日持仓" << pInvestorPosition->YdPosition << "今日持仓" << pInvestorPosition->Position << "多头冻结" << pInvestorPosition->LongFrozen << "空头冻结" << pInvestorPosition->ShortFrozen << "开仓冻结金额" << pInvestorPosition->LongFrozenAmount << "开仓冻结金额" << pInvestorPosition->ShortFrozenAmount << "开仓量" << pInvestorPosition->OpenVolume << "平仓量" << pInvestorPosition->CloseVolume << "开仓金额" << pInvestorPosition->OpenAmount << "平仓金额" << pInvestorPosition->CloseAmount << "持仓成本" << pInvestorPosition->PositionCost << "上次占用的保证金" << pInvestorPosition->PreMargin << "占用的保证金" << pInvestorPosition->UseMargin << "冻结的保证金" << pInvestorPosition->FrozenMargin << "冻结的资金" << pInvestorPosition->FrozenCash << "冻结的手续费" << pInvestorPosition->FrozenCommission << "资金差额" << pInvestorPosition->CashIn << "手续费" << pInvestorPosition->Commission << "平仓盈亏" << pInvestorPosition->CloseProfit << "持仓盈亏" << pInvestorPosition->PositionProfit << "上次结算价" << pInvestorPosition->PreSettlementPrice << "本次结算价" << pInvestorPosition->SettlementPrice << "交易日" << pInvestorPosition->TradingDay << "结算编号" << pInvestorPosition->SettlementID << "开仓成本" << pInvestorPosition->OpenCost << "交易所保证金" << pInvestorPosition->ExchangeMargin << "组合成交形成的持仓" << pInvestorPosition->CombPosition << "组合多头冻结" << pInvestorPosition->CombLongFrozen << "组合空头冻结" << pInvestorPosition->CombShortFrozen << "逐日盯市平仓盈亏" << pInvestorPosition->CloseProfitByDate << "逐笔对冲平仓盈亏" << pInvestorPosition->CloseProfitByTrade << "今日持仓" << pInvestorPosition->TodayPosition << "保证金率" << pInvestorPosition->MarginRateByMoney << "保证金率(按手数)" << pInvestorPosition->MarginRateByVolume << "执行冻结" << pInvestorPosition->StrikeFrozen << "执行冻结金额" << pInvestorPosition->StrikeFrozenAmount << "放弃执行冻结" << pInvestorPosition->AbandonFrozen;
center_p->log.insert("请求查询投资者持仓响应", str.str());
}
if (bIsLast == true)
{
center_p->flag[33] = 1;
}
center_p->handles[3].notify();
}

///请求查询资金账户响应
void class_center::class_trader_spi::OnRspQryTradingAccount(CThostFtdcTradingAccountField* pTradingAccount, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
	std::stringstream str;
if(pRspInfo != nullptr)
{
str << "请求查询资金账户响应" << center_p->zm.zm(pRspInfo->ErrorMsg) << "id" << pRspInfo->ErrorID<<std::endl;
}

if (pTradingAccount != nullptr)
{
memcpy(&center_p->trading_account, pTradingAccount, sizeof(CThostFtdcTradingAccountField));

str << "经纪公司代码" << pTradingAccount->BrokerID << "投资者帐号" << pTradingAccount->AccountID << "上次质押金额" << pTradingAccount->PreMortgage << "上次信用额度" << pTradingAccount->PreCredit << "上次存款额" << pTradingAccount->PreDeposit << "上次结算准备金" << pTradingAccount->PreBalance << "上次占用的保证金" << pTradingAccount->PreMargin << "利息基数" << pTradingAccount->InterestBase << "利息收入" << pTradingAccount->Interest << "入金金额" << pTradingAccount->Deposit << "出金金额" << pTradingAccount->Withdraw << "冻结的保证金" << pTradingAccount->FrozenMargin << "冻结的资金" << pTradingAccount->FrozenCash << "冻结的手续费" << pTradingAccount->FrozenCommission << "当前保证金总额" << pTradingAccount->CurrMargin << "资金差额" << pTradingAccount->CashIn << "手续费" << pTradingAccount->Commission << "平仓盈亏" << pTradingAccount->CloseProfit << "持仓盈亏" << pTradingAccount->PositionProfit << "期货结算准备金" << pTradingAccount->Balance << "可用资金" << pTradingAccount->Available << "可取资金" << pTradingAccount->WithdrawQuota << "基本准备金" << pTradingAccount->Reserve << "交易日" << pTradingAccount->TradingDay << "结算编号" << pTradingAccount->SettlementID << "信用额度" << pTradingAccount->Credit << "质押金额" << pTradingAccount->Mortgage << "交易所保证金" << pTradingAccount->ExchangeMargin << "投资者交割保证金" << pTradingAccount->DeliveryMargin << "交易所交割保证金" << pTradingAccount->ExchangeDeliveryMargin << "保底期货结算准备金" << pTradingAccount->ReserveBalance << "币种代码" << pTradingAccount->CurrencyID << "上次货币质入金额" << pTradingAccount->PreFundMortgageIn << "上次货币质出金额" << pTradingAccount->PreFundMortgageOut << "货币质入金额" << pTradingAccount->FundMortgageIn << "货币质出金额" << pTradingAccount->FundMortgageOut << "货币质押余额" << pTradingAccount->FundMortgageAvailable << "可质押货币金额" << pTradingAccount->MortgageableFund << "特殊产品占用保证金" << pTradingAccount->SpecProductMargin << "特殊产品冻结保证金" << pTradingAccount->SpecProductFrozenMargin << "特殊产品手续费" << pTradingAccount->SpecProductCommission << "特殊产品冻结手续费" << pTradingAccount->SpecProductFrozenCommission << "特殊产品持仓盈亏" << pTradingAccount->SpecProductPositionProfit << "特殊产品平仓盈亏" << pTradingAccount->SpecProductCloseProfit << "根据持仓盈亏算法计算的特殊产品持仓盈亏" << pTradingAccount->SpecProductPositionProfitByAlg << "特殊产品交易所保证金" << pTradingAccount->SpecProductExchangeMargin;
}

if (bIsLast == true)
{
center_p->flag[35] = 1;
}
center_p->handles[4].notify();

center_p->log.insert("请求查询资金账户响应", str.str());
}

///请求查询投资者响应
void class_center::class_trader_spi::OnRspQryInvestor(CThostFtdcInvestorField* pInvestor, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询交易编码响应
void class_center::class_trader_spi::OnRspQryTradingCode(CThostFtdcTradingCodeField* pTradingCode, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询合约保证金率响应
void class_center::class_trader_spi::OnRspQryInstrumentMarginRate(CThostFtdcInstrumentMarginRateField* pInstrumentMarginRate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
 {
	 std::stringstream xx;
if(pRspInfo != nullptr)
{
xx<<"错误id:"<<pRspInfo->ErrorID<<"错误信息:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<std::endl;
}
if(pInstrumentMarginRate != nullptr)
{
xx<<"投资者范围"<<pInstrumentMarginRate->InvestorRange<<"经纪公司代码"<<pInstrumentMarginRate->BrokerID<<"投资者代码"<<pInstrumentMarginRate->InvestorID<<"投机套保标志"<<pInstrumentMarginRate->HedgeFlag<<"多头保证金率"<<pInstrumentMarginRate->LongMarginRatioByMoney<<"多头保证金费"<<pInstrumentMarginRate->LongMarginRatioByVolume<<"空头保证金率"<<pInstrumentMarginRate->ShortMarginRatioByMoney<<"空头保证金费"<<pInstrumentMarginRate->ShortMarginRatioByVolume<<"是否相对交易所收取"<<pInstrumentMarginRate->IsRelative<<"交易所代码"<<pInstrumentMarginRate->ExchangeID<<"投资单元代码"<<pInstrumentMarginRate->InvestUnitID<<"合约代码"<<pInstrumentMarginRate->InstrumentID;
std::cout<<"多头保证金率"<<pInstrumentMarginRate->LongMarginRatioByMoney<<"多头保证金费"<<pInstrumentMarginRate->LongMarginRatioByVolume<<"空头保证金率"<<pInstrumentMarginRate->ShortMarginRatioByMoney<<"空头保证金费"<<pInstrumentMarginRate->ShortMarginRatioByVolume<<"合约代码"<<pInstrumentMarginRate->InstrumentID<<std::endl;
}
center_p->log.insert("请求查询合约保证金率响应",xx.str());
}


///请求查询合约手续费率响应
void class_center::class_trader_spi::OnRspQryInstrumentCommissionRate(CThostFtdcInstrumentCommissionRateField* pInstrumentCommissionRate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
	std::stringstream str;
if(pInstrumentCommissionRate!= nullptr)
{
str<<"合约代码"<<pInstrumentCommissionRate->InstrumentID<<"投资者范围"<<pInstrumentCommissionRate->InvestorRange<<"经纪公司代码"<<pInstrumentCommissionRate->BrokerID<<"开仓手续费率"<<pInstrumentCommissionRate->OpenRatioByMoney<<"开仓手续费"<<pInstrumentCommissionRate->OpenRatioByVolume<<"平仓手续费率"<<pInstrumentCommissionRate->CloseRatioByMoney<<"平仓手续费"<<pInstrumentCommissionRate->CloseRatioByVolume<<"平今手续费率"<<pInstrumentCommissionRate->CloseTodayRatioByMoney<<"平今手续费"<<pInstrumentCommissionRate->CloseTodayRatioByVolume;
}
std::cout<<"请求查询合约手续费率响应\n"<<str.str()<<std::endl;
center_p->log.insert("请求查询合约手续费率响应",str.str());
}

///请求查询交易所响应
void class_center::class_trader_spi::OnRspQryExchange(CThostFtdcExchangeField* pExchange, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询产品响应
void class_center::class_trader_spi::OnRspQryProduct(CThostFtdcProductField* pProduct, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询合约响应
void class_center::class_trader_spi::OnRspQryInstrument(CThostFtdcInstrumentField* pInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
if (pInstrument != nullptr)
{
center_p->hy_map[pInstrument->InstrumentID] = *pInstrument;//插入map

std::stringstream str;
str<<"合约代码"<<pInstrument->InstrumentID<<"交易所代码"<<pInstrument->ExchangeID<<"合约名称"<<center_p->zm.zm(pInstrument->InstrumentName)<<"合约在交易所的代码"<<pInstrument->ExchangeInstID<<"产品代码"<<pInstrument->ProductID<<"产品类型"<<pInstrument->ProductClass<<"交割年份"<<pInstrument->DeliveryYear<<"交割月"<<pInstrument->DeliveryMonth<<"市价单最大下单量"<<pInstrument->MaxMarketOrderVolume<<"市价单最小下单量"<<pInstrument->MinMarketOrderVolume<<"限价单最大下单量"<<pInstrument->MaxLimitOrderVolume<<"限价单最小下单量"<<pInstrument->MinLimitOrderVolume<<"合约数量乘数"<<pInstrument->VolumeMultiple<<"最小变动价位"<<pInstrument->PriceTick<<"创建日"<<pInstrument->CreateDate<<"上市日"<<pInstrument->OpenDate<<"到期日"<<pInstrument->ExpireDate<<"开始交割日"<<pInstrument->StartDelivDate<<"结束交割日"<<pInstrument->EndDelivDate<<"合约生命周期状态"<<pInstrument->InstLifePhase<<"当前是否交易"<<pInstrument->IsTrading<<"持仓类型"<<pInstrument->PositionType<<"持仓日期类型"<<pInstrument->PositionDateType<<"多头保证金率"<<pInstrument->LongMarginRatio<<"空头保证金率"<<pInstrument->ShortMarginRatio<<"是否使用大额单边保证金算法"<<pInstrument->MaxMarginSideAlgorithm<<"基础商品代码"<<pInstrument->UnderlyingInstrID<<"执行价"<<pInstrument->StrikePrice<<"期权类型"<<pInstrument->OptionsType<<"合约基础商品乘数"<<pInstrument->UnderlyingMultiple<<"组合类型"<<pInstrument->CombinationType;
center_p->log.insert("请求查询合约响应",str.str());
}
if (bIsLast == true)
{
center_p->flag[31] = 1;
}
center_p->handles[1].notify();
}

///请求查询行情响应
void class_center::class_trader_spi::OnRspQryDepthMarketData(CThostFtdcDepthMarketDataField* pDepthMarketData, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询投资者结算结果响应
void class_center::class_trader_spi::OnRspQrySettlementInfo(CThostFtdcSettlementInfoField* pSettlementInfo, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
if(pSettlementInfo != nullptr)
{
center_p->SettlementInfo_str += pSettlementInfo->Content;
}
if(bIsLast == true)
{
center_p->flag[41] = 1;
center_p->log.insert("请求查询投资者结算结果响应",center_p->zm.zm(center_p->SettlementInfo_str.c_str()) );
//std::cout<<"请求查询投资者结算结果响应:\n"<<center_p->zm.zm(center_p->SettlementInfo_str)<<std::endl;
//center_p->SettlementInfo_str="";
}
}

///请求查询转帐银行响应
void class_center::class_trader_spi::OnRspQryTransferBank(CThostFtdcTransferBankField* pTransferBank, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询投资者持仓明细响应
void class_center::class_trader_spi::OnRspQryInvestorPositionDetail(CThostFtdcInvestorPositionDetailField* pInvestorPositionDetail, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询客户通知响应
void class_center::class_trader_spi::OnRspQryNotice(CThostFtdcNoticeField* pNotice, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询结算信息确认响应`
void class_center::class_trader_spi::OnRspQrySettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField* pSettlementInfoConfirm, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
	std::stringstream xx;
if (pRspInfo != nullptr)
{
center_p->flag[27] = 1;
xx<<"请求查询结算信息确认响应 消息正文:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"ID"<<pRspInfo->ErrorID<<std::endl;
} else {
	std::cout <<"请求查询结算信息确认响应 指针无效"  << std::endl;
center_p->flag[27] = 1;
}
if(pSettlementInfoConfirm !=nullptr)
{
xx<<"经纪公司代码"<<pSettlementInfoConfirm->BrokerID<<"投资者代码"<<pSettlementInfoConfirm->InvestorID<<"确认日期"<<pSettlementInfoConfirm->ConfirmDate<<"确认时间"<<pSettlementInfoConfirm->ConfirmTime<<"结算编号"<<pSettlementInfoConfirm->SettlementID<<"投资者帐号"<<pSettlementInfoConfirm->AccountID<<"币种代码"<<pSettlementInfoConfirm->CurrencyID;
}
center_p->log.insert("请求查询结算信息确认响应",xx.str());
std::cout<<xx.str()<<std::endl;
}

///请求查询投资者持仓明细响应
void class_center::class_trader_spi::OnRspQryInvestorPositionCombineDetail(CThostFtdcInvestorPositionCombineDetailField* pInvestorPositionCombineDetail, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///查询保证金监管系统经纪公司资金账户密钥响应
void class_center::class_trader_spi::OnRspQryCFMMCTradingAccountKey(CThostFtdcCFMMCTradingAccountKeyField* pCFMMCTradingAccountKey, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询仓单折抵信息响应
void class_center::class_trader_spi::OnRspQryEWarrantOffset(CThostFtdcEWarrantOffsetField* pEWarrantOffset, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询投资者品种/跨品种保证金响应
void class_center::class_trader_spi::OnRspQryInvestorProductGroupMargin(CThostFtdcInvestorProductGroupMarginField* pInvestorProductGroupMargin, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询交易所保证金率响应
void class_center::class_trader_spi::OnRspQryExchangeMarginRate(CThostFtdcExchangeMarginRateField* pExchangeMarginRate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询交易所调整保证金率响应
void class_center::class_trader_spi::OnRspQryExchangeMarginRateAdjust(CThostFtdcExchangeMarginRateAdjustField* pExchangeMarginRateAdjust, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询汇率响应
void class_center::class_trader_spi::OnRspQryExchangeRate(CThostFtdcExchangeRateField* pExchangeRate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询二级代理操作员银期权限响应
void class_center::class_trader_spi::OnRspQrySecAgentACIDMap(CThostFtdcSecAgentACIDMapField* pSecAgentACIDMap, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询产品报价汇率
void class_center::class_trader_spi::OnRspQryProductExchRate(CThostFtdcProductExchRateField* pProductExchRate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询产品组
void class_center::class_trader_spi::OnRspQryProductGroup(CThostFtdcProductGroupField* pProductGroup, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询做市商合约手续费率响应
void class_center::class_trader_spi::OnRspQryMMInstrumentCommissionRate(CThostFtdcMMInstrumentCommissionRateField* pMMInstrumentCommissionRate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询做市商期权合约手续费响应
void class_center::class_trader_spi::OnRspQryMMOptionInstrCommRate(CThostFtdcMMOptionInstrCommRateField* pMMOptionInstrCommRate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询报单手续费响应
void class_center::class_trader_spi::OnRspQryInstrumentOrderCommRate(CThostFtdcInstrumentOrderCommRateField* pInstrumentOrderCommRate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询资金账户响应
void class_center::class_trader_spi::OnRspQrySecAgentTradingAccount(CThostFtdcTradingAccountField* pTradingAccount, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询二级代理商资金校验模式响应
void class_center::class_trader_spi::OnRspQrySecAgentCheckMode(CThostFtdcSecAgentCheckModeField* pSecAgentCheckMode, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询期权交易成本响应
void class_center::class_trader_spi::OnRspQryOptionInstrTradeCost(CThostFtdcOptionInstrTradeCostField* pOptionInstrTradeCost, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{

if(pRspInfo != nullptr)
{
	std::cout<<"错误信息:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<",错误id:"<<pRspInfo->ErrorID<<std::endl;
}
	if(pOptionInstrTradeCost != nullptr)
{
//	std::cout<<"经纪公司代码"
//	<<pOptionInstrTradeCost->BrokerID
//	<<"投资者代码"
//	<<pOptionInstrTradeCost->InvestorID
//	<<"保留的无效字段"
//	<<pOptionInstrTradeCost->reserve1
//	<<"投机套保标志"
//	<<pOptionInstrTradeCost->HedgeFlag
	std::cout	<<"期权合约保证金不变部分"
<<pOptionInstrTradeCost->FixedMargin
	<<"期权合约最小保证金"
	<<pOptionInstrTradeCost->MiniMargin
	<<"期权合约权利金"
	<<pOptionInstrTradeCost->Royalty
	<<"交易所期权合约保证金不变部分"
	<<pOptionInstrTradeCost->ExchFixedMargin
	<<"交易所期权合约最小保证金"
	<<pOptionInstrTradeCost->ExchMiniMargin
	<<"交易所代码"
	<<pOptionInstrTradeCost->ExchangeID
	<<"投资单元代码"
	<<pOptionInstrTradeCost->InvestUnitID
	<<"合约代码"
	<<pOptionInstrTradeCost->InstrumentID;
}

}


///请求查询期权合约手续费响应
void class_center::class_trader_spi::OnRspQryOptionInstrCommRate(CThostFtdcOptionInstrCommRateField* pOptionInstrCommRate, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
	std::cout<<"请求查询期权合约手续费响应"<<std::endl;
if(pRspInfo !=nullptr)
{
	std::cout<<"信息:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<",id:"<<pRspInfo->ErrorID<<std::endl;
}

if(pOptionInstrCommRate !=nullptr)
{
	std::cout<<"保留的无效字段"
		<<pOptionInstrCommRate->reserve1;
	std::cout<<"投资者范围"
		<<pOptionInstrCommRate->InvestorRange;
	std::cout<<"经纪公司代码"
		<<pOptionInstrCommRate->BrokerID;
	std::cout<<"投资者代码"
		<<pOptionInstrCommRate->InvestorID;
	std::cout<<"开仓手续费率"
		<<pOptionInstrCommRate->OpenRatioByMoney;
	std::cout<<"开仓手续费"
		<<pOptionInstrCommRate->OpenRatioByVolume;
	std::cout<<"平仓手续费率"
		<<pOptionInstrCommRate->CloseRatioByMoney;
	std::cout<<"平仓手续费"
		<<pOptionInstrCommRate->CloseRatioByVolume;
	std::cout<<"平今手续费率"
		<<pOptionInstrCommRate->CloseTodayRatioByMoney;
	std::cout<<"平今手续费"
		<<pOptionInstrCommRate->CloseTodayRatioByVolume;
	std::cout<<"执行手续费率"
		<<pOptionInstrCommRate->StrikeRatioByMoney;
	std::cout<<"执行手续费"
		<<pOptionInstrCommRate->StrikeRatioByVolume;
	std::cout<<"交易所代码"
		<<pOptionInstrCommRate->ExchangeID;
	std::cout<<"投资单元代码"
		<<pOptionInstrCommRate->InvestUnitID;
	std::cout<<"合约代码"
		<<pOptionInstrCommRate->InstrumentID;
	std::cout<<std::endl;
}
}


///请求查询执行宣告响应
void class_center::class_trader_spi::OnRspQryExecOrder(CThostFtdcExecOrderField* pExecOrder, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询询价响应
void class_center::class_trader_spi::OnRspQryForQuote(CThostFtdcForQuoteField* pForQuote, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询报价响应
void class_center::class_trader_spi::OnRspQryQuote(CThostFtdcQuoteField* pQuote, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询期权自对冲响应
void class_center::class_trader_spi::OnRspQryOptionSelfClose(CThostFtdcOptionSelfCloseField* pOptionSelfClose, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询投资单元响应
void class_center::class_trader_spi::OnRspQryInvestUnit(CThostFtdcInvestUnitField* pInvestUnit, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询组合合约安全系数响应
void class_center::class_trader_spi::OnRspQryCombInstrumentGuard(CThostFtdcCombInstrumentGuardField* pCombInstrumentGuard, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询申请组合响应
void class_center::class_trader_spi::OnRspQryCombAction(CThostFtdcCombActionField* pCombAction, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询转帐流水响应
void class_center::class_trader_spi::OnRspQryTransferSerial(CThostFtdcTransferSerialField* pTransferSerial, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询银期签约关系响应
void class_center::class_trader_spi::OnRspQryAccountregister(CThostFtdcAccountregisterField* pAccountregister, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
	std::cout<<"请求查询银期签约关系响应"<<std::endl;
if(pRspInfo !=nullptr)
{
	std::cout<<"信息:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<",id:"<<pRspInfo->ErrorID<<std::endl;
}

if(pAccountregister !=nullptr)
{
	std::cout<<"交易日期"<<pAccountregister->TradeDay;
	std::cout<<"银行编码"<<pAccountregister->BankID;
	std::cout<<"银行分支机构编码"<<pAccountregister->BankBranchID;
std::cout<<"银行帐号"<<pAccountregister->BankAccount;
std::cout<<"期货公司编码"<<pAccountregister->BrokerID;
std::cout<<"期货公司分支机构编码"<<pAccountregister->BrokerBranchID;
std::cout<<"投资者帐号"<<pAccountregister->AccountID;
std::cout<<"证件类型"<<pAccountregister->IdCardType;
std::cout<<"证件号码"<<pAccountregister->IdentifiedCardNo;
std::cout<<"客户姓名"<<center_p->zm.zm(pAccountregister->CustomerName);
std::cout<<"币种代码"<<pAccountregister->CurrencyID;
std::cout<<"开销户类别"<<pAccountregister->OpenOrDestroy;
std::cout<<"签约日期"<<pAccountregister->RegDate;
std::cout<<"解约日期"<<pAccountregister->OutDate;
std::cout<<"交易ID"<<pAccountregister->TID;
std::cout<<"客户类型"<<pAccountregister->CustType;
std::cout<<"银行帐号类型"<<pAccountregister->BankAccType;
std::cout<<"长客户姓名"<<center_p->zm.zm(pAccountregister->LongCustomerName);
std::cout<<std::endl;
}
}


///错误应答
void class_center::class_trader_spi::OnRspError(CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
	std::stringstream xx;
if(pRspInfo !=nullptr)
{
xx<<"错误信息:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"ID"<<pRspInfo->ErrorID;
}
center_p->log.insert("交易错误应答",xx.str());
}

///报单通知
void class_center::class_trader_spi::OnRtnOrder(CThostFtdcOrderField* pOrder) 
{
center_p->position_map[pOrder->InstrumentID].insert_order(*pOrder);

std::stringstream str2;
str2 << "经纪公司代码" << pOrder->BrokerID << "合约代码" << pOrder->InstrumentID << "报单引用" << pOrder->OrderRef << "用户代码" << pOrder->UserID << "报单价格条件" << pOrder->OrderPriceType << "买卖方向" << pOrder->Direction << "组合开平标志" << pOrder->CombOffsetFlag << "组合投机套保标志" << pOrder->CombHedgeFlag << "价格" << pOrder->LimitPrice << "数量" << pOrder->VolumeTotalOriginal << "有效期类型" << pOrder->TimeCondition << "GTD日期" << pOrder->GTDDate << "成交量类型" << pOrder->VolumeCondition << "最小成交量" << pOrder->MinVolume << "触发条件" << pOrder->ContingentCondition << "止损价" << pOrder->StopPrice << "强平原因" << pOrder->ForceCloseReason << "自动挂起标志" << pOrder->IsAutoSuspend << "业务单元" << pOrder->BusinessUnit << "请求编号" << pOrder->RequestID << "本地报单编号" << pOrder->OrderLocalID << "交易所代码" << pOrder->ExchangeID << "会员代码" << pOrder->ParticipantID << "客户代码" << pOrder->ClientID << "合约在交易所的代码" << pOrder->ExchangeInstID << "交易所交易员代码" << pOrder->TraderID << "安装编号" << pOrder->InstallID << "报单提交状态" << pOrder->OrderSubmitStatus << "报单提示序号" << pOrder->NotifySequence << "交易日" << pOrder->TradingDay << "结算编号" << pOrder->SettlementID << "报单编号" << pOrder->OrderSysID << "报单来源" << pOrder->OrderSource << "报单状态" << pOrder->OrderStatus << "报单类型" << pOrder->OrderType << "今成交数量" << pOrder->VolumeTraded << "剩余数量" << pOrder->VolumeTotal << "报单日期" << pOrder->InsertDate << "委托时间" << pOrder->InsertTime << "激活时间" << pOrder->ActiveTime << "挂起时间" << pOrder->SuspendTime << "最后修改时间" << pOrder->UpdateTime << "撤销时间" << pOrder->CancelTime << "最后修改交易所交易员代码" << pOrder->ActiveTraderID << "结算会员编号" << pOrder->ClearingPartID << "序号" << pOrder->SequenceNo << "前置编号" << pOrder->FrontID << "会话编号" << pOrder->SessionID << "用户端产品信息" << pOrder->UserProductInfo << "状态信息" << center_p->zm.zm(pOrder->StatusMsg) << "用户强评标志" << pOrder->UserForceClose << "操作用户代码" << pOrder->ActiveUserID << "经纪公司报单编号" << pOrder->BrokerOrderSeq << "相关报单" << pOrder->RelativeOrderSysID << "郑商所成交数量" << pOrder->ZCETotalTradedVolume << "互换单标志" << pOrder->IsSwapOrder << "营业部编号" << pOrder->BranchID << "投资单元代码" << pOrder->InvestUnitID << "资金账号" << pOrder->AccountID << "币种代码" << pOrder->CurrencyID << "IP地址" << pOrder->IPAddress << "Mac地址" << pOrder->MacAddress;

center_p->log.insert("报单通知", str2.str());
center_p->handles[5].notify();
}

///成交通知
void class_center::class_trader_spi::OnRtnTrade(CThostFtdcTradeField* pTrade) 
{
center_p->position_map[pTrade->InstrumentID].insert_trade(*pTrade);

std::stringstream str2;
str2 << "经纪公司代码" << pTrade->BrokerID << "合约代码" << pTrade->InstrumentID << "报单引用" << pTrade->OrderRef << "用户代码" << pTrade->UserID << "交易所代码" << pTrade->ExchangeID << "成交编号" << pTrade->TradeID << "买卖方向" << pTrade->Direction << "报单编号" << pTrade->OrderSysID << "会员代码" << pTrade->ParticipantID << "客户代码" << pTrade->ClientID << "交易角色" << pTrade->TradingRole << "合约在交易所的代码" << pTrade->ExchangeInstID << "开平标志" << pTrade->OffsetFlag << "投机套保标志" << pTrade->HedgeFlag << "价格" << pTrade->Price << "数量" << pTrade->Volume << "成交时期" << pTrade->TradeDate << "成交时间" << pTrade->TradeTime << "成交类型" << pTrade->TradeType << "成交价来源" << pTrade->PriceSource << "交易所交易员代码" << pTrade->TraderID << "本地报单编号" << pTrade->OrderLocalID << "结算会员编号" << pTrade->ClearingPartID << "业务单元" << pTrade->BusinessUnit << "序号" << pTrade->SequenceNo << "交易日" << pTrade->TradingDay << "结算编号" << pTrade->SettlementID << "经纪公司报单编号" << pTrade->BrokerOrderSeq << "成交来源" << pTrade->TradeSource;
center_p->log.insert("成交通知", str2.str());
if(center_p->flag[3] != 0)
{
str2.clear();
str2.str("");
str2 <<"成交时间" << pTrade->TradeTime<<std::endl
<< pTrade->UserID<<std::endl
<<pTrade->InstrumentID<<"买卖方向" << pTrade->Direction << "价格" << pTrade->Price << "数量" << pTrade->Volume ;
center_p->log.msg(str2.str());
}
center_p->handles[6].notify();
center_p->flag[33] = 0;
}

///报单录入错误回报
void class_center::class_trader_spi::OnErrRtnOrderInsert(CThostFtdcInputOrderField* pInputOrder, CThostFtdcRspInfoField* pRspInfo) {}

///报单操作错误回报
void class_center::class_trader_spi::OnErrRtnOrderAction(CThostFtdcOrderActionField* pOrderAction, CThostFtdcRspInfoField* pRspInfo) {}

///合约交易状态通知
void class_center::class_trader_spi::OnRtnInstrumentStatus(CThostFtdcInstrumentStatusField* pInstrumentStatus) 
{
	std::stringstream str;
if(pInstrumentStatus != nullptr)
{
center_p->instrument_status_map[pInstrumentStatus->InstrumentID] = *pInstrumentStatus;

//修改行情状态
for(auto it = center_p->hy_map.begin();it != center_p->hy_map.end();++it)
{
if(strcmp(it->second.ProductID, pInstrumentStatus->InstrumentID) == 0)
{
center_p->tick_status_map[it->first] = pInstrumentStatus->InstrumentStatus;
} 
}


str<<"交易所代码"<<pInstrumentStatus->ExchangeID<<"合约在交易所的代码"<<pInstrumentStatus->ExchangeInstID<<"结算组代码"<<pInstrumentStatus->SettlementGroupID<<"合约代码"<<pInstrumentStatus->InstrumentID<<"合约交易状态"<<pInstrumentStatus->InstrumentStatus<<"交易阶段编号"<<pInstrumentStatus->TradingSegmentSN<<"进入本状态时间"<<pInstrumentStatus->EnterTime<<"进入本状态原因"<<pInstrumentStatus->EnterReason;
}
center_p->log.insert("合约交易状态通知",str.str());
}

///交易所公告通知
void class_center::class_trader_spi::OnRtnBulletin(CThostFtdcBulletinField* pBulletin) 
{
	std::stringstream str;

if(pBulletin !=nullptr)
{
str<<"交易所代码"<<pBulletin->ExchangeID<<"交易日"<<pBulletin->TradingDay<<"公告编号"<<pBulletin->BulletinID<<"序列号"<<pBulletin->SequenceNo<<"公告类型"<<pBulletin->NewsType<<"紧急程度"<<pBulletin->NewsUrgency<<"发送时间"<<pBulletin->SendTime<<"消息摘要"<<pBulletin->Abstract<<"消息来源"<<pBulletin->ComeFrom<<"消息正文"<<center_p->zm.zm(pBulletin->Content)<<"WEB地址"<<pBulletin->URLLink<<"市场代码"<<pBulletin->MarketID;
}
center_p->log.insert("交易所公告通知",str.str());
if(center_p->flag[3] != 0)
{
	center_p->log.msg(str.str());
}
std::cout<<"交易所公告通知"<<str.str();
}

///交易通知
void class_center::class_trader_spi::OnRtnTradingNotice(CThostFtdcTradingNoticeInfoField* pTradingNoticeInfo) 
{
	std::stringstream str;

if(pTradingNoticeInfo !=nullptr)
{
str<<"经纪公司代码"<<pTradingNoticeInfo->BrokerID<<"投资者代码"<<pTradingNoticeInfo->InvestorID<<"发送时间"<<pTradingNoticeInfo->SendTime<<"消息正文"<<center_p->zm.zm(pTradingNoticeInfo->FieldContent)<<"序列系列号"<<pTradingNoticeInfo->SequenceSeries<<"序列号"<<pTradingNoticeInfo->SequenceNo;
}
center_p->log.insert("交易通知",str.str());
if(center_p->flag[3] != 0)
{
center_p->log.msg(str.str());
}
std::cout<<"交易通知"<<str.str()<<std::endl;
}

///提示条件单校验错误
void class_center::class_trader_spi::OnRtnErrorConditionalOrder(CThostFtdcErrorConditionalOrderField* pErrorConditionalOrder) {}

///执行宣告通知
void class_center::class_trader_spi::OnRtnExecOrder(CThostFtdcExecOrderField* pExecOrder) 
{
	std::stringstream xx;
if(pExecOrder != nullptr)
{
	xx<<"经纪公司代码"<<pExecOrder->BrokerID<<"投资者代码"<<pExecOrder->InvestorID<<"执行宣告引用"<<pExecOrder->ExecOrderRef<<"用户代码"<<pExecOrder->UserID<<"数量"<<pExecOrder->Volume<<"请求编号"<<pExecOrder->RequestID<<"业务单元"<<pExecOrder->BusinessUnit<<"开平标志"<<pExecOrder->OffsetFlag<<"投机套保标志"<<pExecOrder->HedgeFlag<<"执行类型"<<pExecOrder->ActionType<<"保留头寸申请的持仓方向"<<pExecOrder->PosiDirection<<"期权行权后生成的头寸是否自动平仓"<<pExecOrder->CloseFlag<<"本地执行宣告编号"<<pExecOrder->ExecOrderLocalID<<"交易所代码"<<pExecOrder->ExchangeID<<"会员代码"<<pExecOrder->ParticipantID<<"客户代码"<<pExecOrder->ClientID<<"交易所交易员代码"<<pExecOrder->TraderID<<"安装编号"<<pExecOrder->InstallID<<"执行宣告提交状态"<<pExecOrder->OrderSubmitStatus<<"报单提示序号"<<pExecOrder->NotifySequence<<"交易日"<<pExecOrder->TradingDay<<"结算编号"<<pExecOrder->SettlementID<<"执行宣告编号"<<pExecOrder->ExecOrderSysID<<"报单日期"<<pExecOrder->InsertDate<<"插入时间"<<pExecOrder->InsertTime<<"撤销时间"<<pExecOrder->CancelTime<<"执行结果"<<pExecOrder->ExecResult<<"结算会员编号"<<pExecOrder->ClearingPartID<<"序号"<<pExecOrder->SequenceNo<<"前置编号"<<pExecOrder->FrontID<<"会话编号"<<pExecOrder->SessionID<<"用户端产品信息"<<pExecOrder->UserProductInfo<<"状态信息"<<center_p->zm.zm(pExecOrder->StatusMsg)<<"操作用户代码"<<pExecOrder->ActiveUserID<<"经纪公司报单编号"<<pExecOrder->BrokerExecOrderSeq<<"营业部编号"<<pExecOrder->BranchID<<"投资单元代码"<<pExecOrder->InvestUnitID<<"资金账号"<<pExecOrder->AccountID<<"币种代码"<<pExecOrder->CurrencyID<<"Mac地址"<<pExecOrder->MacAddress<<"合约代码"<<pExecOrder->InstrumentID<<"合约在交易所的代码"<<pExecOrder->ExchangeInstID<<"IP地址"<<pExecOrder->IPAddress;
}
	center_p->log.insert("执行宣告通知",xx.str());
}

///执行宣告录入错误回报
void class_center::class_trader_spi::OnErrRtnExecOrderInsert(CThostFtdcInputExecOrderField* pInputExecOrder, CThostFtdcRspInfoField* pRspInfo) 
{
	std::stringstream sem;
	if(pRspInfo != nullptr)
{
	sem<<"执行宣告录入错误回报"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"ID"<<pRspInfo->ErrorID<<std::endl;
}
	if(pInputExecOrder != nullptr)
{
	sem<<"经纪公司代码"<<pInputExecOrder->BrokerID
		<<"投资者代码"<<pInputExecOrder->InvestorID
		<<"执行宣告引用"<<pInputExecOrder->ExecOrderRef
		<<"用户代码"<<pInputExecOrder->UserID
		<<"数量"<<pInputExecOrder->Volume
		<<"请求编号"<<pInputExecOrder->RequestID
		<<"业务单元"<<pInputExecOrder->BusinessUnit
		<<"开平标志"<<pInputExecOrder->OffsetFlag
		<<"投机套保标志"<<pInputExecOrder->HedgeFlag
		<<"执行类型"<<pInputExecOrder->ActionType
		<<"保留头寸申请的持仓方向"<<pInputExecOrder->PosiDirection
		<<"期权行权后生成的头寸是否自动平仓"<<pInputExecOrder->CloseFlag
		<<"交易所代码"<<pInputExecOrder->ExchangeID
		<<"投资单元代码"<<pInputExecOrder->InvestUnitID
		<<"资金账号"<<pInputExecOrder->AccountID
		<<"币种代码"<<pInputExecOrder->CurrencyID
		<<"交易编码"<<pInputExecOrder->ClientID
		<<"Mac地址"<<pInputExecOrder->MacAddress
		<<"合约代码"<<pInputExecOrder->InstrumentID
		<<"IP地址"<<pInputExecOrder->IPAddress<<std::endl;
}
//std::cout<<sem.str();
center_p->log.insert("执行宣告录入错误回报", sem.str() );
}


///执行宣告操作错误回报
void class_center::class_trader_spi::OnErrRtnExecOrderAction(CThostFtdcExecOrderActionField* pExecOrderAction, CThostFtdcRspInfoField* pRspInfo) 
{
	std::stringstream sem;
if(pRspInfo !=nullptr)
{
sem<<"执行宣告操作错误回std::cout<<sem.str();报"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"ID"<<pRspInfo->ErrorID<<std::endl;
}
if(pExecOrderAction !=nullptr)
{
sem<<"经纪公司代码"<<pExecOrderAction->BrokerID<<"投资者代码"<<pExecOrderAction->InvestorID<<"执行宣告操作引用"<<pExecOrderAction->ExecOrderActionRef<<"执行宣告引用"<<pExecOrderAction->ExecOrderRef<<"请求编号"<<pExecOrderAction->RequestID<<"前置编号"<<pExecOrderAction->FrontID<<"会话编号"<<pExecOrderAction->SessionID<<"交易所代码"<<pExecOrderAction->ExchangeID<<"执行宣告操作编号"<<pExecOrderAction->ExecOrderSysID<<"操作标志"<<pExecOrderAction->ActionFlag<<"操作日期"<<pExecOrderAction->ActionDate<<"操作时间"<<pExecOrderAction->ActionTime<<"交易所交易员代码"<<pExecOrderAction->TraderID<<"安装编号"<<pExecOrderAction->InstallID<<"本地执行宣告编号"<<pExecOrderAction->ExecOrderLocalID<<"操作本地编号"<<pExecOrderAction->ActionLocalID<<"会员代码"<<pExecOrderAction->ParticipantID<<"客户代码"<<pExecOrderAction->ClientID<<"业务单元"<<pExecOrderAction->BusinessUnit<<"报单操作状态"<<pExecOrderAction->OrderActionStatus<<"用户代码"<<pExecOrderAction->UserID<<"执行类型"<<pExecOrderAction->ActionType<<"状态信息"<<pExecOrderAction->StatusMsg<<"保留的无效字段"<<pExecOrderAction->reserve1<<"营业部编号"<<pExecOrderAction->BranchID<<"投资单元代码"<<pExecOrderAction->InvestUnitID<<"保留的无效字段"<<pExecOrderAction->reserve2<<"Mac地址"<<pExecOrderAction->MacAddress<<"合约代码"<<pExecOrderAction->InstrumentID<<"IP地址"<<pExecOrderAction->IPAddress<<std::endl;
}
std::cout<<sem.str();
center_p->log.insert("执行宣告操作错误回报", sem.str() );
}

///询价录入错误回报
void class_center::class_trader_spi::OnErrRtnForQuoteInsert(CThostFtdcInputForQuoteField* pInputForQuote, CThostFtdcRspInfoField* pRspInfo) {}

///报价通知
void class_center::class_trader_spi::OnRtnQuote(CThostFtdcQuoteField* pQuote) {}

///报价录入错误回报
void class_center::class_trader_spi::OnErrRtnQuoteInsert(CThostFtdcInputQuoteField* pInputQuote, CThostFtdcRspInfoField* pRspInfo) {}

///报价操作错误回报
void class_center::class_trader_spi::OnErrRtnQuoteAction(CThostFtdcQuoteActionField* pQuoteAction, CThostFtdcRspInfoField* pRspInfo) {}

///询价通知
void class_center::class_trader_spi::OnRtnForQuoteRsp(CThostFtdcForQuoteRspField* pForQuoteRsp) {}

///保证金监控中心用户令牌
void class_center::class_trader_spi::OnRtnCFMMCTradingAccountToken(CThostFtdcCFMMCTradingAccountTokenField* pCFMMCTradingAccountToken) {}

///批量报单操作错误回报
void class_center::class_trader_spi::OnErrRtnBatchOrderAction(CThostFtdcBatchOrderActionField* pBatchOrderAction, CThostFtdcRspInfoField* pRspInfo) {}

///期权自对冲通知
void class_center::class_trader_spi::OnRtnOptionSelfClose(CThostFtdcOptionSelfCloseField* pOptionSelfClose) 
{
	std::stringstream xx;
xx<<"经纪公司代码"<<pOptionSelfClose->BrokerID<<"投资者代码"<<pOptionSelfClose->InvestorID<<"期权自对冲引用"<<pOptionSelfClose->OptionSelfCloseRef<<"用户代码"<<pOptionSelfClose->UserID<<"数量"<<pOptionSelfClose->Volume<<"请求编号"<<pOptionSelfClose->RequestID<<"业务单元"<<pOptionSelfClose->BusinessUnit<<"投机套保标志"<<pOptionSelfClose->HedgeFlag<<"期权行权的头寸是否自对冲"<<pOptionSelfClose->OptSelfCloseFlag<<"本地期权自对冲编号"<<pOptionSelfClose->OptionSelfCloseLocalID<<"交易所代码"<<pOptionSelfClose->ExchangeID<<"会员代码"<<pOptionSelfClose->ParticipantID<<"客户代码"<<pOptionSelfClose->ClientID<<"交易所交易员代码"<<pOptionSelfClose->TraderID<<"安装编号"<<pOptionSelfClose->InstallID<<"期权自对冲提交状态"<<pOptionSelfClose->OrderSubmitStatus<<"报单提示序号"<<pOptionSelfClose->NotifySequence<<"交易日"<<pOptionSelfClose->TradingDay<<"结算编号"<<pOptionSelfClose->SettlementID<<"期权自对冲编号"<<pOptionSelfClose->OptionSelfCloseSysID<<"报单日期"<<pOptionSelfClose->InsertDate<<"插入时间"<<pOptionSelfClose->InsertTime<<"撤销时间"<<pOptionSelfClose->CancelTime<<"自对冲结果"<<pOptionSelfClose->ExecResult<<"结算会员编号"<<pOptionSelfClose->ClearingPartID<<"序号"<<pOptionSelfClose->SequenceNo<<"前置编号"<<pOptionSelfClose->FrontID<<"会话编号"<<pOptionSelfClose->SessionID<<"用户端产品信息"<<pOptionSelfClose->UserProductInfo<<"状态信息"<<center_p->zm.zm(pOptionSelfClose->StatusMsg)<<"操作用户代码"<<pOptionSelfClose->ActiveUserID<<"经纪公司报单编号"<<pOptionSelfClose->BrokerOptionSelfCloseSeq<<"营业部编号"<<pOptionSelfClose->BranchID<<"投资单元代码"<<pOptionSelfClose->InvestUnitID<<"资金账号"<<pOptionSelfClose->AccountID<<"币种代码"<<pOptionSelfClose->CurrencyID<<"Mac地址"<<pOptionSelfClose->MacAddress<<"合约代码"<<pOptionSelfClose->InstrumentID<<"合约在交易所的代码"<<pOptionSelfClose->ExchangeInstID<<"IP地址"<<pOptionSelfClose->IPAddress;
center_p->log.insert("期权自对冲通知",xx.str());
}

///期权自对冲录入错误回报
void class_center::class_trader_spi::OnErrRtnOptionSelfCloseInsert(CThostFtdcInputOptionSelfCloseField* pInputOptionSelfClose, CThostFtdcRspInfoField* pRspInfo) 
{
	std::cout<<"期权自对冲录入错误回报"<<std::endl;
	std::stringstream xx;
xx<<"经纪公司代码"<<pInputOptionSelfClose->BrokerID<<"投资者代码"<<pInputOptionSelfClose->InvestorID<<"期权自对冲引用"<<pInputOptionSelfClose->OptionSelfCloseRef<<"用户代码"<<pInputOptionSelfClose->UserID<<"数量"<<pInputOptionSelfClose->Volume<<"请求编号"<<pInputOptionSelfClose->RequestID<<"业务单元"<<pInputOptionSelfClose->BusinessUnit<<"投机套保标志"<<pInputOptionSelfClose->HedgeFlag<<"期权行权的头寸是否自对冲"<<pInputOptionSelfClose->OptSelfCloseFlag<<"交易所代码"<<pInputOptionSelfClose->ExchangeID<<"投资单元代码"<<pInputOptionSelfClose->InvestUnitID<<"资金账号"<<pInputOptionSelfClose->AccountID<<"币种代码"<<pInputOptionSelfClose->CurrencyID<<"交易编码"<<pInputOptionSelfClose->ClientID<<"Mac地址"<<pInputOptionSelfClose->MacAddress<<"合约代码"<<pInputOptionSelfClose->InstrumentID<<"IP地址"<<pInputOptionSelfClose->IPAddress;
center_p->log.insert("期权自对冲录入错误回报",xx.str());
}

///期权自对冲操作错误回报
void class_center::class_trader_spi::OnErrRtnOptionSelfCloseAction(CThostFtdcOptionSelfCloseActionField* pOptionSelfCloseAction, CThostFtdcRspInfoField* pRspInfo) {}

///申请组合通知
void class_center::class_trader_spi::OnRtnCombAction(CThostFtdcCombActionField* pCombAction) 
{
if(pCombAction != nullptr)
{
std::cout<<"经纪公司代码"
<<pCombAction->BrokerID
<<"投资者代码"
<<pCombAction->InvestorID
//<<"保留的无效字段"
//<<pCombAction->reserve1
<<"组合引用"
<<pCombAction->CombActionRef
<<"用户代码"
<<pCombAction->UserID
<<"买卖方向"
<<pCombAction->Direction
<<"数量"
<<pCombAction->Volume
<<"组合指令方向"
<<pCombAction->CombDirection
<<"投机套保标志"
<<pCombAction->HedgeFlag
<<"本地申请组合编号"
<<pCombAction->ActionLocalID
<<"交易所代码"
<<pCombAction->ExchangeID
<<"会员代码"
<<pCombAction->ParticipantID
<<"客户代码"
<<pCombAction->ClientID
<<"保留的无效字段"
<<pCombAction->reserve2
<<"交易所交易员代码"
<<pCombAction->TraderID
<<"安装编号"
<<pCombAction->InstallID
<<"组合状态"
<<pCombAction->ActionStatus
<<"报单提示序号"
<<pCombAction->NotifySequence
<<"交易日"
<<pCombAction->TradingDay
<<"结算编号"
<<pCombAction->SettlementID
<<"序号"
<<pCombAction->SequenceNo
<<"前置编号"
<<pCombAction->FrontID
<<"会话编号"
<<pCombAction->SessionID
<<"用户端产品信息"
<<pCombAction->UserProductInfo
<<"状态信息"
<<center_p->zm.zm(pCombAction->StatusMsg)
//<<"保留的无效字段"
//<<pCombAction->reserve3
<<"Mac地址"
<<pCombAction->MacAddress
<<"组合编号"
<<pCombAction->ComTradeID
<<"营业部编号"
<<pCombAction->BranchID
<<"投资单元代码"
<<pCombAction->InvestUnitID
<<"合约代码"
<<pCombAction->InstrumentID
<<"合约在交易所的代码"
<<pCombAction->ExchangeInstID
<<"IP地址"
<<pCombAction->IPAddress
<<std::endl;
}

}


///申请组合录入错误回报
void class_center::class_trader_spi::OnErrRtnCombActionInsert(CThostFtdcInputCombActionField* pInputCombAction, CThostFtdcRspInfoField* pRspInfo)
{
if(pRspInfo != nullptr)
{
	std::cout<<"申请组合录入错误回报:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<"ID:"<<pRspInfo->ErrorID<<std::endl;
}
}

///请求查询签约银行响应
void class_center::class_trader_spi::OnRspQryContractBank(CThostFtdcContractBankField* pContractBank, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询预埋单响应
void class_center::class_trader_spi::OnRspQryParkedOrder(CThostFtdcParkedOrderField* pParkedOrder, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询预埋撤单响应
void class_center::class_trader_spi::OnRspQryParkedOrderAction(CThostFtdcParkedOrderActionField* pParkedOrderAction, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询交易通知响应
void class_center::class_trader_spi::OnRspQryTradingNotice(CThostFtdcTradingNoticeField* pTradingNotice, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询经纪公司交易参数响应
void class_center::class_trader_spi::OnRspQryBrokerTradingParams(CThostFtdcBrokerTradingParamsField* pBrokerTradingParams, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询经纪公司交易算法响应
void class_center::class_trader_spi::OnRspQryBrokerTradingAlgos(CThostFtdcBrokerTradingAlgosField* pBrokerTradingAlgos, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///请求查询监控中心用户令牌
void class_center::class_trader_spi::OnRspQueryCFMMCTradingAccountToken(CThostFtdcQueryCFMMCTradingAccountTokenField* pQueryCFMMCTradingAccountToken, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {}

///银行发起银行资金转期货通知
void class_center::class_trader_spi::OnRtnFromBankToFutureByBank(CThostFtdcRspTransferField* pRspTransfer) {}

///银行发起期货资金转银行通知
void class_center::class_trader_spi::OnRtnFromFutureToBankByBank(CThostFtdcRspTransferField* pRspTransfer) {}

///银行发起冲正银行转期货通知
void class_center::class_trader_spi::OnRtnRepealFromBankToFutureByBank(CThostFtdcRspRepealField* pRspRepeal) {}

///银行发起冲正期货转银行通知
void class_center::class_trader_spi::OnRtnRepealFromFutureToBankByBank(CThostFtdcRspRepealField* pRspRepeal) {}

///期货发起银行资金转期货通知
void class_center::class_trader_spi::OnRtnFromBankToFutureByFuture(CThostFtdcRspTransferField* pRspTransfer) 
{
	std::cout<<"期货发起银行资金转期货通知"<<std::endl;
if(pRspTransfer != nullptr)
{
	std::cout<<"业务功能码"
	<<pRspTransfer->TradeCode;
	std::cout<<"银行代码"
	<<pRspTransfer->BankID;
	std::cout<<"银行分支机构代码"
	<<pRspTransfer->BankBranchID;
	std::cout<<"期商代码"
	<<pRspTransfer->BrokerID;
	std::cout<<"期商分支机构代码"
	<<pRspTransfer->BrokerBranchID;
	std::cout<<"交易日期"
	<<pRspTransfer->TradeDate;
	std::cout<<"交易时间"
	<<pRspTransfer->TradeTime;
	std::cout<<"银行流水号"
	<<pRspTransfer->BankSerial;
	std::cout<<"交易系统日期" 
	<<pRspTransfer->TradingDay;
	std::cout<<"银期平台消息流水号"
	<<pRspTransfer->PlateSerial;
	std::cout<<"最后分片标志"
	<<pRspTransfer->LastFragment;
	std::cout<<"会话号"
	<<pRspTransfer->SessionID;
	std::cout<<"客户姓名"
	<<center_p->zm.zm(pRspTransfer->CustomerName);
	std::cout<<"证件类型"
	<<pRspTransfer->IdCardType;
	std::cout<<"证件号码"
	<<pRspTransfer->IdentifiedCardNo;
	std::cout<<"客户类型"
	<<pRspTransfer->CustType;
	std::cout<<"银行帐号"
	<<pRspTransfer->BankAccount;
	std::cout<<"银行密码"
	<<pRspTransfer->BankPassWord;
	std::cout<<"投资者帐号"
	<<pRspTransfer->AccountID;
	std::cout<<"期货密码"
	<<pRspTransfer->Password;
	std::cout<<"安装编号"
	<<pRspTransfer->InstallID;
	std::cout<<"期货公司流水号"
	<<pRspTransfer->FutureSerial;
	std::cout<<"用户标识"
	<<pRspTransfer->UserID;
	std::cout<<"验证客户证件号码标志"
	<<pRspTransfer->VerifyCertNoFlag;
	std::cout<<"币种代码"
	<<pRspTransfer->CurrencyID;
	std::cout<<"转帐金额"
	<<pRspTransfer->TradeAmount;
	std::cout<<"期货可取金额"
	<<pRspTransfer->FutureFetchAmount;
	std::cout<<"费用支付标志"
	<<pRspTransfer->FeePayFlag;
	std::cout<<"应收客户费用"
	<<pRspTransfer->CustFee;
	std::cout<<"应收期货公司费用"
	<<pRspTransfer->BrokerFee;
	std::cout<<"发送方给接收方的消息"
	<<pRspTransfer->Message;
	std::cout<<"摘要"
	<<pRspTransfer->Digest;
	std::cout<<"银行帐号类型"
	<<pRspTransfer->BankAccType;
	std::cout<<"渠道标志"
	<<pRspTransfer->DeviceID;
	std::cout<<"期货单位帐号类型"
	<<pRspTransfer->BankSecuAccType;
	std::cout<<"期货公司银行编码"
	<<pRspTransfer->BrokerIDByBank;
	std::cout<<"期货单位帐号"
	<<pRspTransfer->BankSecuAcc;
	std::cout<<"银行密码标志"
	<<pRspTransfer->BankPwdFlag;
	std::cout<<"期货资金密码核对标志"
	<<pRspTransfer->SecuPwdFlag;
	std::cout<<"交易柜员"
	<<pRspTransfer->OperNo;
	std::cout<<"请求编号"
	<<pRspTransfer->RequestID;
	std::cout<<"交易ID"
	<<pRspTransfer->TID;
	std::cout<<"转账交易状态"
	<<pRspTransfer->TransferStatus;
	std::cout<<"错误代码"
	<<pRspTransfer->ErrorID;
	std::cout<<"错误信息"
	<<center_p->zm.zm(pRspTransfer->ErrorMsg);
	std::cout<<"长客户姓名"
	<<center_p->zm.zm(pRspTransfer->LongCustomerName);
	std::cout<<std::endl;
}
}


///期货发起期货资金转银行通知
void class_center::class_trader_spi::OnRtnFromFutureToBankByFuture(CThostFtdcRspTransferField* pRspTransfer) 
{
	std::cout<<"期货发起期货资金转银行通知"<<std::endl;
if(pRspTransfer != nullptr)
{
	std::cout<<"业务功能码"
	<<pRspTransfer->TradeCode;
	std::cout<<"银行代码"
	<<pRspTransfer->BankID;
	std::cout<<"银行分支机构代码"
	<<pRspTransfer->BankBranchID;
	std::cout<<"期商代码"
	<<pRspTransfer->BrokerID;
	std::cout<<"期商分支机构代码"
	<<pRspTransfer->BrokerBranchID;
	std::cout<<"交易日期"
	<<pRspTransfer->TradeDate;
	std::cout<<"交易时间"
	<<pRspTransfer->TradeTime;
	std::cout<<"银行流水号"
	<<pRspTransfer->BankSerial;
	std::cout<<"交易系统日期" 
	<<pRspTransfer->TradingDay;
	std::cout<<"银期平台消息流水号"
	<<pRspTransfer->PlateSerial;
	std::cout<<"最后分片标志"
	<<pRspTransfer->LastFragment;
	std::cout<<"会话号"
	<<pRspTransfer->SessionID;
	std::cout<<"客户姓名"
	<<center_p->zm.zm(pRspTransfer->CustomerName);
	std::cout<<"证件类型"
	<<pRspTransfer->IdCardType;
	std::cout<<"证件号码)"
	<<pRspTransfer->IdentifiedCardNo;
	std::cout<<"客户类型"
	<<pRspTransfer->CustType;
	std::cout<<"银行帐号"
	<<pRspTransfer->BankAccount;
	std::cout<<"银行密码"
	<<pRspTransfer->BankPassWord;
	std::cout<<"投资者帐号"
	<<pRspTransfer->AccountID;
	std::cout<<"期货密码"
	<<pRspTransfer->Password;
	std::cout<<"安装编号"
	<<pRspTransfer->InstallID;
	std::cout<<"期货公司流水号"
	<<pRspTransfer->FutureSerial;
	std::cout<<"用户标识"
	<<pRspTransfer->UserID;
	std::cout<<"验证客户证件号码标志"
	<<pRspTransfer->VerifyCertNoFlag;
	std::cout<<"币种代码"
	<<pRspTransfer->CurrencyID;
	std::cout<<"转帐金额"
	<<pRspTransfer->TradeAmount;
	std::cout<<"期货可取金额"
	<<pRspTransfer->FutureFetchAmount;
	std::cout<<"费用支付标志"
	<<pRspTransfer->FeePayFlag;
	std::cout<<"应收客户费用"
	<<pRspTransfer->CustFee;
std::cout<<"应收期货公司费用"
	<<pRspTransfer->BrokerFee;
std::cout<<"发送方给接收方的消息"
	<<pRspTransfer->Message;
std::cout<<"摘要"
	<<pRspTransfer->Digest;
std::cout<<"银行帐号类型"
	<<pRspTransfer->BankAccType;
std::cout<<"渠道标志"
	<<pRspTransfer->DeviceID;
std::cout<<"期货单位帐号类型"
	<<pRspTransfer->BankSecuAccType;
std::cout<<"期货公司银行编码"
	<<pRspTransfer->BrokerIDByBank;
std::cout<<"期货单位帐号"
	<<pRspTransfer->BankSecuAcc;
std::cout<<"银行密码标志"
	<<pRspTransfer->BankPwdFlag;
std::cout<<"期货资金密码核对标志"
	<<pRspTransfer->SecuPwdFlag;
std::cout<<"交易柜员"
	<<pRspTransfer->OperNo;
std::cout<<"请求编号"
	<<pRspTransfer->RequestID;
std::cout<<"交易ID"
	<<pRspTransfer->TID;
std::cout<<"转账交易状态"
	<<pRspTransfer->TransferStatus;
std::cout<<"错误代码"
	<<pRspTransfer->ErrorID;
std::cout<<"错误信息"
	<<center_p->zm.zm(pRspTransfer->ErrorMsg);
std::cout<<"长客户姓名"
	<<center_p->zm.zm(pRspTransfer->LongCustomerName);
std::cout<<std::endl;
}
}

///系统运行时期货端手工发起冲正银行转期货请求，银行处理完毕后报盘发回的通知
void class_center::class_trader_spi::OnRtnRepealFromBankToFutureByFutureManual(CThostFtdcRspRepealField* pRspRepeal) {}

///系统运行时期货端手工发起冲正期货转银行请求，银行处理完毕后报盘发回的通知
void class_center::class_trader_spi::OnRtnRepealFromFutureToBankByFutureManual(CThostFtdcRspRepealField* pRspRepeal) {}

///期货发起查询银行余额通知
void class_center::class_trader_spi::OnRtnQueryBankBalanceByFuture(CThostFtdcNotifyQueryAccountField* pNotifyQueryAccount) 
{
	std::cout<<"期货发起查询银行余额通知"<<std::endl;

if(pNotifyQueryAccount != nullptr)
{
	std::cout<<"业务功能码"
		<<pNotifyQueryAccount->TradeCode;
	std::cout<<"银行代码"
		<<pNotifyQueryAccount->BankID;
	std::cout<<"银行分支机构代码"
		<<pNotifyQueryAccount->BankBranchID;
	std::cout<<"期商代码"
		<<pNotifyQueryAccount->BrokerID;
	std::cout<<"期商分支机构代码"
		<<pNotifyQueryAccount->BrokerBranchID;
	std::cout<<"交易日期"
		<<pNotifyQueryAccount->TradeDate;
	std::cout<<"交易时间"
		<<pNotifyQueryAccount->TradeTime;
	std::cout<<"银行流水号"
		<<pNotifyQueryAccount->BankSerial;
	std::cout<<"交易系统日期 "
		<<pNotifyQueryAccount->TradingDay;
	std::cout<<"银期平台消息流水号"
		<<pNotifyQueryAccount->PlateSerial;
	std::cout<<"最后分片标志"
		<<pNotifyQueryAccount->LastFragment;
	std::cout<<"会话号"
		<<pNotifyQueryAccount->SessionID;
	std::cout<<"客户姓名"
		<<center_p->zm.zm(pNotifyQueryAccount->CustomerName);
	std::cout<<"证件类型"
		<<pNotifyQueryAccount->IdCardType;
	std::cout<<"证件号码"
		<<pNotifyQueryAccount->IdentifiedCardNo;
	std::cout<<"客户类型"
		<<pNotifyQueryAccount->CustType;
	std::cout<<"银行帐号"
		<<pNotifyQueryAccount->BankAccount;
	std::cout<<"银行密码"
		<<pNotifyQueryAccount->BankPassWord;
	std::cout<<"投资者帐号"
		<<pNotifyQueryAccount->AccountID;
	std::cout<<"期货密码"
		<<pNotifyQueryAccount->Password;
	std::cout<<"期货公司流水号"
		<<pNotifyQueryAccount->FutureSerial;
	std::cout<<"安装编号"
		<<pNotifyQueryAccount->InstallID;
	std::cout<<"用户标识"
		<<pNotifyQueryAccount->UserID;
	std::cout<<"验证客户证件号码标志"
		<<pNotifyQueryAccount->VerifyCertNoFlag;
	std::cout<<"币种代码"
		<<pNotifyQueryAccount->CurrencyID;
	std::cout<<"摘要"
		<<pNotifyQueryAccount->Digest;
	std::cout<<"银行帐号类型"
		<<pNotifyQueryAccount->BankAccType;
	std::cout<<"渠道标志"
		<<pNotifyQueryAccount->DeviceID;
	std::cout<<"期货单位帐号类型"
		<<pNotifyQueryAccount->BankSecuAccType;
	std::cout<<"期货公司银行编码"
		<<pNotifyQueryAccount->BrokerIDByBank;
	std::cout<<"期货单位帐号"
		<<pNotifyQueryAccount->BankSecuAcc;
	std::cout<<"银行密码标志"
		<<pNotifyQueryAccount->BankPwdFlag;
	std::cout<<"期货资金密码核对标志"
		<<pNotifyQueryAccount->SecuPwdFlag;
	std::cout<<"交易柜员"
		<<pNotifyQueryAccount->OperNo;
	std::cout<<"请求编号"
		<<pNotifyQueryAccount->RequestID;
	std::cout<<"交易ID"
		<<pNotifyQueryAccount->TID;
	std::cout<<"银行可用金额"
		<<pNotifyQueryAccount->BankUseAmount;
	std::cout<<"银行可取金额"
		<<pNotifyQueryAccount->BankFetchAmount;
	std::cout<<"错误代码"
		<<pNotifyQueryAccount->ErrorID;
	std::cout<<"错误信息"
		<<center_p->zm.zm(pNotifyQueryAccount->ErrorMsg);
	std::cout<<"长客户姓名"
		<<center_p->zm.zm(pNotifyQueryAccount->LongCustomerName);
	std::cout<<std::endl;
}
}


///期货发起银行资金转期货错误回报
void class_center::class_trader_spi::OnErrRtnBankToFutureByFuture(CThostFtdcReqTransferField* pReqTransfer, CThostFtdcRspInfoField* pRspInfo) 
{
	std::cout<<"期货发起银行资金转期货错误回报"<<std::endl;
}

///期货发起期货资金转银行错误回报
void class_center::class_trader_spi::OnErrRtnFutureToBankByFuture(CThostFtdcReqTransferField* pReqTransfer, CThostFtdcRspInfoField* pRspInfo) 
{
	std::cout<<"期货发起期货资金转银行错误回报"<<std::endl;
}

///系统运行时期货端手工发起冲正银行转期货错误回报
void class_center::class_trader_spi::OnErrRtnRepealBankToFutureByFutureManual(CThostFtdcReqRepealField* pReqRepeal, CThostFtdcRspInfoField* pRspInfo) {}

///系统运行时期货端手工发起冲正期货转银行错误回报
void class_center::class_trader_spi::OnErrRtnRepealFutureToBankByFutureManual(CThostFtdcReqRepealField* pReqRepeal, CThostFtdcRspInfoField* pRspInfo) {}

///期货发起查询银行余额错误回报
void class_center::class_trader_spi::OnErrRtnQueryBankBalanceByFuture(CThostFtdcReqQueryAccountField* pReqQueryAccount, CThostFtdcRspInfoField* pRspInfo) 
{
	std::cout<<"期货发起查询银行余额错误回报"<<std::endl;
if(pRspInfo != nullptr)
{
	std::cout<<"信息"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<pRspInfo->ErrorID<<std::endl;	
}

if(pReqQueryAccount !=nullptr)
{
	std::cout<<"业务功能码"
		<<pReqQueryAccount->TradeCode;
	std::cout<<"银行代码"
		<<pReqQueryAccount->BankID;
	std::cout<<"银行分支机构代码"
		<<pReqQueryAccount->BankBranchID;
	std::cout<<"期商代码"
		<<pReqQueryAccount->BrokerID;
	std::cout<<"期商分支机构代码"
		<<pReqQueryAccount->BrokerBranchID;
	std::cout<<"交易日期"
		<<pReqQueryAccount->TradeDate;
	std::cout<<"交易时间"
		<<pReqQueryAccount->TradeTime;
	std::cout<<"银行流水号"
		<<pReqQueryAccount->BankSerial;
	std::cout<<"交易系统日期 "
		<<pReqQueryAccount->TradingDay;
	std::cout<<"银期平台消息流水号"
		<<pReqQueryAccount->PlateSerial;
	std::cout<<"最后分片标志"
		<<pReqQueryAccount->LastFragment;
	std::cout<<"会话号"
		<<pReqQueryAccount->SessionID;
	std::cout<<"客户姓名"
		<<pReqQueryAccount->CustomerName;
	std::cout<<"证件类型"
		<<pReqQueryAccount->IdCardType;
	std::cout<<"证件号码"
		<<pReqQueryAccount->IdentifiedCardNo;
	std::cout<<"客户类型"
		<<pReqQueryAccount->CustType;
	std::cout<<"银行帐号"
		<<pReqQueryAccount->BankAccount;
	std::cout<<"银行密码"
		<<pReqQueryAccount->BankPassWord;
	std::cout<<"投资者帐号"
		<<pReqQueryAccount->AccountID;
	std::cout<<"期货密码"
		<<pReqQueryAccount->Password;
	std::cout<<"期货公司流水号"
		<<pReqQueryAccount->FutureSerial;
	std::cout<<"安装编号"
		<<pReqQueryAccount->InstallID;
	std::cout<<"用户标识"
		<<pReqQueryAccount->UserID;
	std::cout<<"验证客户证件号码标志"
		<<pReqQueryAccount->VerifyCertNoFlag;
	std::cout<<"币种代码"
		<<pReqQueryAccount->CurrencyID;
	std::cout<<"摘要"
		<<pReqQueryAccount->Digest;
	std::cout<<"银行帐号类型"
		<<pReqQueryAccount->BankAccType;
	std::cout<<"渠道标志"
		<<pReqQueryAccount->DeviceID;
	std::cout<<"期货单位帐号类型"
		<<pReqQueryAccount->BankSecuAccType;
	std::cout<<"期货公司银行编码"
		<<pReqQueryAccount->BrokerIDByBank;
	std::cout<<"期货单位帐号"
		<<pReqQueryAccount->BankSecuAcc;
	std::cout<<"银行密码标志"
		<<pReqQueryAccount->BankPwdFlag;
	std::cout<<"期货资金密码核对标志"
		<<pReqQueryAccount->SecuPwdFlag;
	std::cout<<"交易柜员"
		<<pReqQueryAccount->OperNo;
	std::cout<<"请求编号"
		<<pReqQueryAccount->RequestID;
	std::cout<<"交易ID"
		<<pReqQueryAccount->TID;
	std::cout<<"长客户姓名"
		<<pReqQueryAccount->LongCustomerName;
	std::cout<<std::endl;
}
}


///期货发起冲正银行转期货请求，银行处理完毕后报盘发回的通知
void class_center::class_trader_spi::OnRtnRepealFromBankToFutureByFuture(CThostFtdcRspRepealField* pRspRepeal) {}

///期货发起冲正期货转银行请求，银行处理完毕后报盘发回的通知
void class_center::class_trader_spi::OnRtnRepealFromFutureToBankByFuture(CThostFtdcRspRepealField* pRspRepeal) {}

///期货发起银行资金转期货应答
void class_center::class_trader_spi::OnRspFromBankToFutureByFuture(CThostFtdcReqTransferField* pReqTransfer, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{

	std::cout<<"期货发起银行资金转期货应答"<<std::endl;
if(pRspInfo !=nullptr)
{
	std::cout<<"信息:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<",id:"<<pRspInfo->ErrorID<<std::endl;
}
if(pReqTransfer !=nullptr)
{
	std::cout<<"业务功能码"
	<<pReqTransfer->TradeCode;
	std::cout<<"银行代码"
	<<pReqTransfer->BankID;
	std::cout<<"银行分支机构代码"
	<<pReqTransfer->BankBranchID;
	std::cout<<"期商代码"
	<<pReqTransfer->BrokerID;
	std::cout<<"期商分支机构代码"
	<<pReqTransfer->BrokerBranchID;
	std::cout<<"交易日期"
	<<pReqTransfer->TradeDate;
	std::cout<<"交易时间"
	<<pReqTransfer->TradeTime;
	std::cout<<"银行流水号"
	<<pReqTransfer->BankSerial;
	std::cout<<"交易系统日期" 
	<<pReqTransfer->TradingDay;
	std::cout<<"银期平台消息流水号"
	<<pReqTransfer->PlateSerial;
	std::cout<<"最后分片标志"
	<<pReqTransfer->LastFragment;
	std::cout<<"会话号"
	<<pReqTransfer->SessionID;
	std::cout<<"客户姓名"
	<<pReqTransfer->CustomerName;
	std::cout<<"证件类型"
	<<pReqTransfer->IdCardType;
	std::cout<<"证件号码"
	<<pReqTransfer->IdentifiedCardNo;
	std::cout<<"客户类型"
	<<pReqTransfer->CustType;
	std::cout<<"银行帐号"
	<<pReqTransfer->BankAccount;
	std::cout<<"银行密码"
	<<pReqTransfer->BankPassWord;
	std::cout<<"投资者帐号"
	<<pReqTransfer->AccountID;
	std::cout<<"期货密码"
	<<pReqTransfer->Password;
	std::cout<<"安装编号"
	<<pReqTransfer->InstallID;
	std::cout<<"期货公司流水号"
	<<pReqTransfer->FutureSerial;
	std::cout<<"用户标识"
	<<pReqTransfer->UserID;
	std::cout<<"验证客户证件号码标志"
	<<pReqTransfer->VerifyCertNoFlag;
	std::cout<<"币种代码"
	<<pReqTransfer->CurrencyID;
	std::cout<<"转帐金额"
	<<pReqTransfer->TradeAmount;
	std::cout<<"期货可取金额"
	<<pReqTransfer->FutureFetchAmount;
	std::cout<<"费用支付标志"
	<<pReqTransfer->FeePayFlag;
	std::cout<<"应收客户费用"
	<<pReqTransfer->CustFee;
	std::cout<<"应收期货公司费用"
	<<pReqTransfer->BrokerFee;
	std::cout<<"发送方给接收方的消息"
	<<pReqTransfer->Message;
	std::cout<<"摘要"
	<<pReqTransfer->Digest;
	std::cout<<"银行帐号类型"
	<<pReqTransfer->BankAccType;
	std::cout<<"渠道标志"
	<<pReqTransfer->DeviceID;
	std::cout<<"期货单位帐号类型"
	<<pReqTransfer->BankSecuAccType;
	std::cout<<"期货公司银行编码"
	<<pReqTransfer->BrokerIDByBank;
	std::cout<<"期货单位帐号"
	<<pReqTransfer->BankSecuAcc;
	std::cout<<"银行密码标志"
	<<pReqTransfer->BankPwdFlag;
	std::cout<<"期货资金密码核对标志"
	<<pReqTransfer->SecuPwdFlag;
	std::cout<<"交易柜员"
	<<pReqTransfer->OperNo;
	std::cout<<"请求编号"
	<<pReqTransfer->RequestID;
	std::cout<<"交易ID"
	<<pReqTransfer->TID;
	std::cout<<"转账交易状态"
	<<pReqTransfer->TransferStatus;
	std::cout<<"长客户姓名"
	<<pReqTransfer->LongCustomerName;
	std::cout<<std::endl;
}
}


///期货发起期货资金转银行应答
void class_center::class_trader_spi::OnRspFromFutureToBankByFuture(CThostFtdcReqTransferField* pReqTransfer, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
	std::cout<<"期货发起期货资金转银行应答"<<std::endl;
if(pRspInfo !=nullptr)
{
	std::cout<<"信息:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<",id:"<<pRspInfo->ErrorID<<std::endl;
}
if(pReqTransfer !=nullptr)
{
	std::cout<<"业务功能码"
	<<pReqTransfer->TradeCode;
	std::cout<<"银行代码"
	<<pReqTransfer->BankID;
	std::cout<<"银行分支机构代码"
	<<pReqTransfer->BankBranchID;
	std::cout<<"期商代码"
	<<pReqTransfer->BrokerID;
	std::cout<<"期商分支机构代码"
	<<pReqTransfer->BrokerBranchID;
	std::cout<<"交易日期"
	<<pReqTransfer->TradeDate;
	std::cout<<"交易时间"
	<<pReqTransfer->TradeTime;
	std::cout<<"银行流水号"
	<<pReqTransfer->BankSerial;
	std::cout<<"交易系统日期" 
	<<pReqTransfer->TradingDay;
	std::cout<<"银期平台消息流水号"
	<<pReqTransfer->PlateSerial;
	std::cout<<"最后分片标志"
	<<pReqTransfer->LastFragment;
	std::cout<<"会话号"
	<<pReqTransfer->SessionID;
	std::cout<<"客户姓名"
	<<pReqTransfer->CustomerName;
	std::cout<<"证件类型"
	<<pReqTransfer->IdCardType;
	std::cout<<"证件号码"
	<<pReqTransfer->IdentifiedCardNo;
	std::cout<<"客户类型"
	<<pReqTransfer->CustType;
	std::cout<<"银行帐号"
	<<pReqTransfer->BankAccount;
	std::cout<<"银行密码"
	<<pReqTransfer->BankPassWord;
	std::cout<<"投资者帐号"
	<<pReqTransfer->AccountID;
	std::cout<<"期货密码"
	<<pReqTransfer->Password;
	std::cout<<"安装编号"
	<<pReqTransfer->InstallID;
	std::cout<<"期货公司流水号"
	<<pReqTransfer->FutureSerial;
	std::cout<<"用户标识"
	<<pReqTransfer->UserID;
	std::cout<<"验证客户证件号码标志"
	<<pReqTransfer->VerifyCertNoFlag;
	std::cout<<"币种代码"
	<<pReqTransfer->CurrencyID;
	std::cout<<"转帐金额"
	<<pReqTransfer->TradeAmount;
	std::cout<<"期货可取金额"
	<<pReqTransfer->FutureFetchAmount;
	std::cout<<"费用支付标志"
	<<pReqTransfer->FeePayFlag;
	std::cout<<"应收客户费用"
	<<pReqTransfer->CustFee;
	std::cout<<"应收期货公司费用"
	<<pReqTransfer->BrokerFee;
	std::cout<<"发送方给接收方的消息"
	<<pReqTransfer->Message;
	std::cout<<"摘要"
	<<pReqTransfer->Digest;
	std::cout<<"银行帐号类型"
	<<pReqTransfer->BankAccType;
	std::cout<<"渠道标志"
	<<pReqTransfer->DeviceID;
	std::cout<<"期货单位帐号类型"
	<<pReqTransfer->BankSecuAccType;
	std::cout<<"期货公司银行编码"
	<<pReqTransfer->BrokerIDByBank;
	std::cout<<"期货单位帐号"
	<<pReqTransfer->BankSecuAcc;
	std::cout<<"银行密码标志"
	<<pReqTransfer->BankPwdFlag;
	std::cout<<"期货资金密码核对标志"
	<<pReqTransfer->SecuPwdFlag;
	std::cout<<"交易柜员"
	<<pReqTransfer->OperNo;
	std::cout<<"请求编号"
	<<pReqTransfer->RequestID;
	std::cout<<"交易ID"
	<<pReqTransfer->TID;
	std::cout<<"转账交易状态"
	<<pReqTransfer->TransferStatus;
	std::cout<<"长客户姓名"
	<<pReqTransfer->LongCustomerName;
	std::cout<<std::endl;
}
}


///期货发起查询银行余额应答
void class_center::class_trader_spi::OnRspQueryBankAccountMoneyByFuture(CThostFtdcReqQueryAccountField* pReqQueryAccount, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 
{
	std::cout<<"期货发起查询银行余额应答"<<std::endl;
if(pRspInfo !=nullptr)
{
	std::cout<<"信息"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<pRspInfo->ErrorID<<std::endl;
}

if(pReqQueryAccount !=nullptr)
{
	std::cout<<"业务功能码"
		<<pReqQueryAccount->TradeCode;
	std::cout<<"银行代码"
		<<pReqQueryAccount->BankID;
	std::cout<<"银行分支机构代码"
		<<pReqQueryAccount->BankBranchID;
	std::cout<<"期商代码"
		<<pReqQueryAccount->BrokerID;
	std::cout<<"期商分支机构代码"
		<<pReqQueryAccount->BrokerBranchID;
	std::cout<<"交易日期"
		<<pReqQueryAccount->TradeDate;
	std::cout<<"交易时间"
		<<pReqQueryAccount->TradeTime;
	std::cout<<"银行流水号"
		<<pReqQueryAccount->BankSerial;
	std::cout<<"交易系统日期 "
		<<pReqQueryAccount->TradingDay;
	std::cout<<"银期平台消息流水号"
		<<pReqQueryAccount->PlateSerial;
	std::cout<<"最后分片标志"
		<<pReqQueryAccount->LastFragment;
	std::cout<<"会话号"
		<<pReqQueryAccount->SessionID;
	std::cout<<"客户姓名"
		<<pReqQueryAccount->CustomerName;
	std::cout<<"证件类型"
		<<pReqQueryAccount->IdCardType;
	std::cout<<"证件号码"
		<<pReqQueryAccount->IdentifiedCardNo;
	std::cout<<"客户类型"
		<<pReqQueryAccount->CustType;
	std::cout<<"银行帐号"
		<<pReqQueryAccount->BankAccount;
	std::cout<<"银行密码"
		<<pReqQueryAccount->BankPassWord;
	std::cout<<"投资者帐号"
		<<pReqQueryAccount->AccountID;
	std::cout<<"期货密码"
		<<pReqQueryAccount->Password;
	std::cout<<"期货公司流水号"
		<<pReqQueryAccount->FutureSerial;
	std::cout<<"安装编号"
		<<pReqQueryAccount->InstallID;
	std::cout<<"用户标识"
		<<pReqQueryAccount->UserID;
	std::cout<<"验证客户证件号码标志"
		<<pReqQueryAccount->VerifyCertNoFlag;
	std::cout<<"币种代码"
		<<pReqQueryAccount->CurrencyID;
	std::cout<<"摘要"
		<<pReqQueryAccount->Digest;
	std::cout<<"银行帐号类型"
		<<pReqQueryAccount->BankAccType;
	std::cout<<"渠道标志"
		<<pReqQueryAccount->DeviceID;
	std::cout<<"期货单位帐号类型"
		<<pReqQueryAccount->BankSecuAccType;
	std::cout<<"期货公司银行编码"
		<<pReqQueryAccount->BrokerIDByBank;
	std::cout<<"期货单位帐号"
		<<pReqQueryAccount->BankSecuAcc;
	std::cout<<"银行密码标志"
		<<pReqQueryAccount->BankPwdFlag;
	std::cout<<"期货资金密码核对标志"
		<<pReqQueryAccount->SecuPwdFlag;
	std::cout<<"交易柜员"
		<<pReqQueryAccount->OperNo;
	std::cout<<"请求编号"
		<<pReqQueryAccount->RequestID;
	std::cout<<"交易ID"
		<<pReqQueryAccount->TID;
	std::cout<<"长客户姓名"
		<<pReqQueryAccount->LongCustomerName;
	std::cout<<std::endl;
}
}


///银行发起银期开户通知
void class_center::class_trader_spi::OnRtnOpenAccountByBank(CThostFtdcOpenAccountField* pOpenAccount) {}

///银行发起银期销户通知
void class_center::class_trader_spi::OnRtnCancelAccountByBank(CThostFtdcCancelAccountField* pCancelAccount) {}

///银行发起变更银行账号通知
void class_center::class_trader_spi::OnRtnChangeAccountByBank(CThostFtdcChangeAccountField* pChangeAccount) {}


///请求查询分类合约响应
void class_center::class_trader_spi::OnRspQryClassifiedInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) 
{
if(pRspInfo != nullptr)
{
	std::cout<<"请求查询分类合约响应:"<<center_p->zm.zm(pRspInfo->ErrorMsg)<<",错误id:"<<pRspInfo->ErrorID<<std::endl;
}
if (pInstrument != nullptr)
{
//center_p->hy_map[pInstrument->InstrumentID] = *pInstrument;//插入map

std::stringstream str;
str<<"合约代码"<<pInstrument->InstrumentID<<"交易所代码"<<pInstrument->ExchangeID<<"合约名称"<<center_p->zm.zm(pInstrument->InstrumentName)<<"合约在交易所的代码"<<pInstrument->ExchangeInstID<<"产品代码"<<pInstrument->ProductID<<"产品类型"<<pInstrument->ProductClass<<"交割年份"<<pInstrument->DeliveryYear<<"交割月"<<pInstrument->DeliveryMonth<<"市价单最大下单量"<<pInstrument->MaxMarketOrderVolume<<"市价单最小下单量"<<pInstrument->MinMarketOrderVolume<<"限价单最大下单量"<<pInstrument->MaxLimitOrderVolume<<"限价单最小下单量"<<pInstrument->MinLimitOrderVolume<<"合约数量乘数"<<pInstrument->VolumeMultiple<<"最小变动价位"<<pInstrument->PriceTick<<"创建日"<<pInstrument->CreateDate<<"上市日"<<pInstrument->OpenDate<<"到期日"<<pInstrument->ExpireDate<<"开始交割日"<<pInstrument->StartDelivDate<<"结束交割日"<<pInstrument->EndDelivDate<<"合约生命周期状态"<<pInstrument->InstLifePhase<<"当前是否交易"<<pInstrument->IsTrading<<"持仓类型"<<pInstrument->PositionType<<"持仓日期类型"<<pInstrument->PositionDateType<<"多头保证金率"<<pInstrument->LongMarginRatio<<"空头保证金率"<<pInstrument->ShortMarginRatio<<"是否使用大额单边保证金算法"<<pInstrument->MaxMarginSideAlgorithm<<"基础商品代码"<<pInstrument->UnderlyingInstrID<<"执行价"<<pInstrument->StrikePrice<<"期权类型"<<pInstrument->OptionsType<<"合约基础商品乘数"<<pInstrument->UnderlyingMultiple<<"组合类型"<<pInstrument->CombinationType;
center_p->log.insert("请求查询分类合约响应",str.str());
}

}


///请求组合优惠比例响应
void class_center::class_trader_spi::OnRspQryCombPromotionParam(CThostFtdcCombPromotionParamField *pCombPromotionParam, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}

///投资者风险结算持仓查询响应
void class_center::class_trader_spi::OnRspQryRiskSettleInvstPosition(CThostFtdcRiskSettleInvstPositionField *pRiskSettleInvstPosition, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}

///风险结算产品查询响应
void class_center::class_trader_spi::OnRspQryRiskSettleProductStatus(CThostFtdcRiskSettleProductStatusField *pRiskSettleProductStatus, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}


///SPBM期货合约参数查询响应
void class_center::class_trader_spi::OnRspQrySPBMFutureParameter(CThostFtdcSPBMFutureParameterField *pSPBMFutureParameter, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}

///SPBM期权合约参数查询响应
void class_center::class_trader_spi::OnRspQrySPBMOptionParameter(CThostFtdcSPBMOptionParameterField *pSPBMOptionParameter, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}

///SPBM品种内对锁仓折扣参数查询响应
void class_center::class_trader_spi::OnRspQrySPBMIntraParameter(CThostFtdcSPBMIntraParameterField *pSPBMIntraParameter, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}

///SPBM跨品种抵扣参数查询响应
void class_center::class_trader_spi::OnRspQrySPBMInterParameter(CThostFtdcSPBMInterParameterField *pSPBMInterParameter, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}

///SPBM组合保证金套餐查询响应
void class_center::class_trader_spi::OnRspQrySPBMPortfDefinition(CThostFtdcSPBMPortfDefinitionField *pSPBMPortfDefinition, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}

///投资者SPBM套餐选择查询响应
void class_center::class_trader_spi::OnRspQrySPBMInvestorPortfDef(CThostFtdcSPBMInvestorPortfDefField *pSPBMInvestorPortfDef, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}

///投资者新型组合保证金系数查询响应
void class_center::class_trader_spi::OnRspQryInvestorPortfMarginRatio(CThostFtdcInvestorPortfMarginRatioField *pInvestorPortfMarginRatio, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}

///投资者产品SPBM明细查询响应
void class_center::class_trader_spi::OnRspQryInvestorProdSPBMDetail(CThostFtdcInvestorProdSPBMDetailField *pInvestorProdSPBMDetail, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}

//交易类实现结束


//实现中心类
//中心类构造
class_center::class_center()
{
for (auto i = 0; i < 64; ++i)
{
flag[i] = 0;
}
nrequestid = 0;
frontid=0;
sessionid=0;
orderref=0;
SettlementInfo_str="";
}


//中心类启动函数
void class_center::run(std::string a, std::string b, std::string c, std::string d, std::string e, std::string f)
{
zm.init("UTF-8","GBK");
path_str = a;
broker_str = b;
user_str = c;
password_str = d;
userproductinfo_str = e;
authcode_str = f;


//查询资金账户响应初始化
memset(&trading_account,0,sizeof(CThostFtdcTradingAccountField));

log.init(path_str + "/log");

init();//初始化
std::cout<<"行情api版本:"<<md_api_p->GetApiVersion()<<std::endl<<"交易api版本:"<<trader_api_p->GetApiVersion()<<std::endl;


//读入tick
std::ifstream file(path_str + "/status/tick_map.dat", std::ios::binary);
CThostFtdcDepthMarketDataField tick= { 0 };
while(file.read(reinterpret_cast<char*>(&tick), sizeof(CThostFtdcDepthMarketDataField)) )
{
	tick_map[tick.InstrumentID] = tick;
} 
file.close();


//读入合约
file.open(path_str + "/status/hy_map.dat", std::ios::binary);
CThostFtdcInstrumentField hy= { 0 };
while(file.read(reinterpret_cast<char*>(&hy), sizeof(CThostFtdcInstrumentField)) )
{
	hy_map[hy.InstrumentID] = hy;
} 
file.close();


//读取持仓
file.open(path_str + "/status/position_map.dat", std::ios::binary);
char name[81]= { 0 };
while(file.read(name, sizeof(name)) )
{
file.read(reinterpret_cast<char*>(&position_map[name].value), sizeof(double));
file.read(reinterpret_cast<char*>(&position_map[name].p22), sizeof(CThostFtdcInvestorPositionField) );
file.read(reinterpret_cast<char*>(&position_map[name].p23), sizeof(CThostFtdcInvestorPositionField) );
file.read(reinterpret_cast<char*>(&position_map[name].p12), sizeof(CThostFtdcInvestorPositionField) );
file.read(reinterpret_cast<char*>(&position_map[name].p13), sizeof(CThostFtdcInvestorPositionField) );
}
file.close();


circle_thread = std::thread(circle, this);
log.insert("log", "中心类构造完成");
}

//中心类析构
class_center::~class_center()
{
log.insert("log","中心类对象开始销毁");
flag[0] = 0;

circle_thread.join();
log.insert("log","中心类对象循环函数退出完成");
flag[2] = 0;

std::cout <<"析构交易" << std::endl;
//注销交易回调spi
trader_api_p->RegisterSpi(NULL);
//释放交易api
trader_api_p->Release();
//卸载SPI
delete trader_spi_p;
trader_spi_p = nullptr;
trader_api_p = nullptr;
std::cout << "交易析构完毕" << std::endl;
std::cout << "行情开始析构" << std::endl;
md_api_p->RegisterSpi(NULL);//注销回调spi 
md_api_p->Release();//释放API
delete md_spi_p;//卸载SPI
md_spi_p = nullptr;
md_api_p = nullptr;
std::cout << "行情析构完成" << std::endl;
std::cout<<"开始写行情"<<std::endl;
log.insert("log","开始写行情");
for (auto it = bars_map.begin(); it != bars_map.end(); ++it)
{
it->second.write(path_str + "/bars/" + it->first + ".dat",1000);
it->second.write_txt(path_str + "/bars_txt/" + it->first + ".txt",1000);
it->second.datas.clear();
}
//写TICK
for (auto it = ticks_map.begin(); it != ticks_map.end(); ++it)
{
it->second.write(path_str + "/ticks/" + it->first + ".dat",10000000);
}
std::cout<<"写行情结束"<<std::endl;
//写tick
std::ofstream file(path_str + "/status/tick_map.dat", std::ios::binary);
for(auto pair:tick_map)
{
	file.write(reinterpret_cast<char*>(&pair.second), sizeof(CThostFtdcDepthMarketDataField) );
}
file.close();
//写合约
file.open(path_str + "/status/hy_map.dat", std::ios::binary);
for(auto pair:hy_map)
{
	file.write(reinterpret_cast<char*>(&pair.second), sizeof(CThostFtdcInstrumentField) );
}
file.close();
//写持仓
file.open(path_str + "/status/position_map.dat", std::ios::binary);
for(auto &pair: position_map)
{
char name[81] = { 0 };
snprintf(name, 81, "%s", pair.first.c_str());;
file.write(name, sizeof(name));
file.write(reinterpret_cast<char*>(&pair.second.value), sizeof(double) );
file.write(reinterpret_cast<char*>(&pair.second.p22), sizeof(CThostFtdcInvestorPositionField) );
file.write(reinterpret_cast<char*>(&pair.second.p23), sizeof(CThostFtdcInvestorPositionField) );
file.write(reinterpret_cast<char*>(&pair.second.p12), sizeof(CThostFtdcInvestorPositionField) );
file.write(reinterpret_cast<char*>(&pair.second.p13), sizeof(CThostFtdcInvestorPositionField) );
}
file.close();

log.insert("log","写合约结束，中心类对象销毁");
}

//中心类循环函数实现
unsigned int class_center::circle(class_center* arg)
{

time_t now = time(0);
tm a;
memset(&a, 0, sizeof(tm));

int xt=0,xt_out=0;//心跳
while (arg->flag[0] != 0)
{
	std::this_thread::sleep_for(std::chrono::seconds(1));
if(xt > 300 && arg->flag[6] != 0 && arg->flag[26] != 0 && arg->flag[2] != 0)
{

//写TICKS
for(auto it = arg->ticks_map.begin();it != arg->ticks_map.end();++it)
{
it->second.write(arg->path_str + "/ticks/" + it->first + ".dat",10000000);
}

if(arg->flag[3] != 0)
{
char msg_text[200]={0};
std::snprintf(msg_text, sizeof(msg_text), "%s\n%s\n期货结算准备金%.2f持仓%.2f", get_date_time().c_str(), arg->trading_account.AccountID, arg->trading_account.Balance, arg->trading_account.CurrMargin/arg->trading_account.Balance*100);
arg->log.msg(msg_text);
}
xt=0;
}
xt++;
xt_out++;

if(xt_out > 20)
{
	std::cout<<"心跳超时"<<xt_out<<std::endl;
if(arg->flag[3] != 0)
{
	arg->log.msg(get_date_time() + "\n" +arg->user_str +"\n心跳超时" + std::to_string(xt_out) );
}
	arg->log.insert("log","心跳超时"+std::to_string(xt_out));
}

now = time(0);
a=*localtime(&now);
char date[9] = {0};
strftime(date, sizeof(date), "%Y%m%d", &a);
//交易时段判定
if ( (a.tm_wday > 0 && a.tm_wday < 6) && (a.tm_hour > 8 && a.tm_hour < 11 || a.tm_hour > 12 && a.tm_hour < 15 || a.tm_hour > 20 || (a.tm_min > 49 && (a.tm_hour == 8 || a.tm_hour == 12 || a.tm_hour == 20) || a.tm_min < 36 && (a.tm_hour == 11 || a.tm_hour == 15))) || a.tm_wday > 1 && (a.tm_hour < 2 || a.tm_hour == 2 && a.tm_min < 36))
{
if(std::find(arg->holiday_list.begin(), arg->holiday_list.end(), date) != arg->holiday_list.end())
	{
arg->flag[2] = 0;
	}
else
{
arg->flag[2] = 1;
}
}
else 
{
if(arg->flag[1] == 24)
{
arg->flag[2] = 1;
}
else
{
arg->flag[2] = 0;
}
}

if(arg->flag[2] == 0)
{
xt_out = 0;
}

//写bar
if(a.tm_min == 40 && (a.tm_hour == 2 || a.tm_hour == 11 || a.tm_hour == 15) )
{
for (auto it = arg->bars_map.begin(); it != arg->bars_map.end(); ++it)
{
it->second.write(arg->path_str + "/bars/" + it->first + ".dat",1000);
it->second.write_txt(arg->path_str + "/bars_txt/" + it->first + ".txt",1000);
it->second.datas.clear();
}
//写tick
for (auto it = arg->ticks_map.begin(); it != arg->ticks_map.end(); ++it)
{
it->second.write(arg->path_str + "/ticks/" + it->first + ".dat",100);
}
}

//行情登录
if (arg->flag[6] == 0 && arg->flag[5] == 1 && arg->flag[2] == 1)
{
//登录
CThostFtdcReqUserLoginField jj;
memset(&jj, 0, sizeof(CThostFtdcReqUserLoginField));
strncpy(jj.BrokerID, arg->broker_str.c_str(), arg->broker_str.size() );
strncpy(jj.UserID, arg->user_str.c_str(), arg->user_str.size() );
strncpy(jj.Password, arg->password_str.c_str(), arg->password_str.size() );
arg->md_api_p->ReqUserLogin(&jj, ++arg->nrequestid);
std::cout << "登录行情" << std::endl;
}


//订阅行情
if (arg->flag[6] == 1 && arg->flag[10] == 0 && arg->flag[31] == 1 || arg->flag[11] == 0 && arg->flag[10] == 1 && arg->flag[31] == 1 && xt_out > 100)
{
arg->flag[10] = 1;
xt_out=0;
int j = arg->hy_map.size();
if(j > 0)
{
char** a = new char* [j];
auto it = arg->hy_map.begin();
for (int i = 0; i < j; ++i)
{
a[i] = new char[81];
memset(a[i], 0, 81*sizeof(char));
strncpy(a[i], (*it).first.c_str(), it->first.size() );
++it;
}
arg->md_api_p->SubscribeMarketData(a, j);//订阅行情
for (int i = 0; i < j; ++i)
{
delete[] a[i];
}
delete[] a;
arg->log.insert("log", "订阅了" + std::to_string(j));
std::cout << "订阅了" << std::to_string(j)<<std::endl;
}

//修改行情状态
for(auto it = arg->hy_map.begin();it != arg->hy_map.end();++it)
{
arg->tick_status_map[it->first] = arg->instrument_status_map[it->second.ProductID].InstrumentStatus;
}
}



//更新主力
if(a.tm_hour == 10 && a.tm_min == 0 && arg->flag[15] == 0 && arg->flag[11] != 0)
{
arg->up_hot();
arg->flag[15]=1;
}


//交易登录
if (arg->flag[26] == 0 && arg->flag[25] == 1 && arg->flag[2] == 1)
{
CThostFtdcReqUserLoginField jj;
memset(&jj, 0, sizeof(CThostFtdcReqUserLoginField));
strncpy(jj.BrokerID, arg->broker_str.c_str(), arg->broker_str.size() );
strncpy(jj.UserID, arg->user_str.c_str(), arg->user_str.size() );
strncpy(jj.Password, arg->password_str.c_str(), arg->password_str.size() );
arg->trader_api_p->ReqUserLogin(&jj, ++arg->nrequestid);
}


//请求查询结算信息确认
if (arg->flag[27] == 0 && arg->flag[26] == 1)
{
//请求查询结算信息确认
CThostFtdcQrySettlementInfoConfirmField jsy;
memset(&jsy, 0, sizeof(CThostFtdcQrySettlementInfoConfirmField));
strncpy(jsy.BrokerID, arg->broker_str.c_str(), arg->broker_str.size() );
strncpy(jsy.InvestorID, arg->user_str.c_str(), arg->user_str.size() );
arg->trader_api_p->ReqQrySettlementInfoConfirm(&jsy, ++arg->nrequestid);
arg->log.insert("log", "请求查询结算信息确认");
}


//投资者结算结果确认
if (arg->flag[28] == 0 && arg->flag[27] == 1)
{
//投资者结算结果确认
CThostFtdcSettlementInfoConfirmField jsqr;
memset(&jsqr, 0, sizeof(CThostFtdcSettlementInfoConfirmField));
strncpy(jsqr.BrokerID, arg->broker_str.c_str(), arg->broker_str.size() );
strncpy(jsqr.InvestorID, arg->user_str.c_str(), arg->user_str.size() );
arg->trader_api_p->ReqSettlementInfoConfirm(&jsqr, ++arg->nrequestid);
arg->log.insert("log", "投资者结算结果确认");
}


//查询合约
if (arg->flag[30] == 0 && arg->flag[28] == 1 || arg->flag[31] == 0 && arg->flag[30] == 1 && xt_out > 100)
{
xt_out = 0;
CThostFtdcQryInstrumentField hy;//合约结构体
memset(&hy, 0, sizeof(CThostFtdcQryInstrumentField));//初始化合约结构体便于之后查询

int fh = arg->trader_api_p->ReqQryInstrument(&hy, ++arg->nrequestid);
if (fh == 0)
{
arg->flag[30] = 1;
std::cout << "查询合约" << std::endl;
}
arg->log.insert("log", "查询合约动作");
}


//查询持仓
if (arg->flag[32] == 0 && arg->flag[31] == 1 || arg->flag[33] == 0 && arg->flag[32] == 1 && xt_out > 100)
{

xt_out = 0;
//声明查询持仓对象
CThostFtdcQryInvestorPositionField pQryInvestorPosition;
memset(&pQryInvestorPosition, 0, sizeof(CThostFtdcQryInvestorPositionField));//清空对象
int fh = arg->trader_api_p->ReqQryInvestorPosition(&pQryInvestorPosition, ++arg->nrequestid);
if (fh == 0)
{
arg->flag[32] = 1;
std::cout << "查询持仓" << std::endl;
}
arg->log.insert("log", "查询持仓动作");
}


//查询资金
if (arg->flag[41] == 1 && arg->flag[34] == 0 || arg->flag[34] == 1)
{
xt_out = 0;
CThostFtdcQryTradingAccountField pQryTradingAccount;
memset(&pQryTradingAccount, 0, sizeof(CThostFtdcQryTradingAccountField));//清空结构
int fh = arg->trader_api_p->ReqQryTradingAccount(&pQryTradingAccount, ++arg->nrequestid);
if (fh == 0)
{
arg->flag[34] = 1;
//std::cout << "查询资金动作" << std::endl;
}
//arg->log.insert("log", "查询资金动作");
}


//请求查询投资者结算结果
if(arg->flag[33] == 1 && arg->flag[40] == 0 || arg->flag[41] == 0 && arg->flag[40] == 1 && xt_out > 100)
{
//更新主力合约
//arg->up_hot();

xt_out = 0;
CThostFtdcQrySettlementInfoField pQrySettlementInfo;
memset(&pQrySettlementInfo,0,sizeof(CThostFtdcQrySettlementInfoField));
if(arg->trader_api_p->ReqQrySettlementInfo(&pQrySettlementInfo, arg->nrequestid++) == 0)
{
arg->flag[40] = 1;
}
arg->log.insert("log","请求查询投资者结算结果 动作");
std::cout<<"请求查询投资者结算结果 动作"<<std::endl;
}


//Sleep(1000);
arg->log.sync();
}

return 0;
}

//初始化函数实现
int class_center::init()
{

//建立目录
	std::string str=path_str;
//if(nullptr == opendir(str.c_str()))
//{
//auto return_value=mkdir(str.c_str(),777);
//if(return_value != 0)
//{
//	std::cout<<"建立目录:"<<str<<"失败！返回值:"<<return_value<<std::endl;
//}
//}
create_path(str);

str= path_str + "/configuration";
//if(nullptr == opendir(str.c_str()))
//{
//auto return_value = mkdir(str.c_str(),7<77);
//if(return_value != 0)
//{
//	std::cout<<"建立目录:"<<str<<"失败！返回值:"<<return_value<<std::endl;
//}
//}
create_path(str);

str = path_str + "/md"; 
//if(nullptr == opendir(str.c_str()))
//{
//auto return_value = mkdir(str.c_str(),777);
//if(return_value != 0)
//{
//	std::cout<<"建立目录:"<<str<<"失败！返回值:"<<return_value<<std::endl;
//}
//}
create_path(str);

str = path_str + "/trader";
//if(nullptr == opendir(str.c_str()))
//{
//auto return_value = mkdir(str.c_str(),777);
//if(return_value != 0)
//{
//	std::cout<<"建立目录:"<<str<<"失败！返回值:"<<return_value<<std::endl;
//}
//}
create_path(str);

str = path_str + "/log";
//if(nullptr == opendir(str.c_str() )) 
//{
//auto return_value = mkdir(str.c_str(),777);
//if(return_value != 0)
//{
//	std::cout<<"建立目录:"<<str<<"失败！返回值:"<<return_value<<std::endl;
//}
//}
create_path(str);

str = path_str + "/bars";
//if(nullptr == opendir(str.c_str()))
//{
//auto return_value = mkdir(str.c_str(),777);
//if(return_value != 0)
//{
//	std::cout<<"建立目录:"<<str<<"失败！返回值:"<<return_value<<std::endl;
//}
//}
create_path(str);

str = path_str + "/ticks";
//if(nullptr == opendir(str.c_str()))
//{
//auto return_value = mkdir(str.c_str(),777);
//if(return_value != 0)
//{
//	std::cout<<"建立目录:"<<str<<"失败！返回值:"<<return_value<<std::endl;
//}
//}
create_path(str);

str = path_str + "/bars_txt";
//if(nullptr == opendir(str.c_str()))
//{
//auto return_value = mkdir(str.c_str(),777);
//if(return_value != 0)
//{
//	std::cout<<"建立目录:"<<str<<"失败！返回值:"<<return_value<<std::endl;
//}
//}
create_path(str);


str = path_str + "/status";
//if(nullptr == opendir(str.c_str()))
//{
//auto return_value = mkdir(str.c_str(),777);
//if(return_value != 0)
//{
//	std::cout<<"建立目录:"<<str<<"失败！返回值:"<<return_value<<std::endl;
//}
//}
create_path(str);

str = path_str + "/0000";
//if(nullptr == opendir(str.c_str()))
//{
//auto return_value = mkdir(str.c_str(),777);
//if(return_value != 0)
//{
//	std::cout<<"建立目录:"<<str<<"失败！返回值:"<<return_value<<std::endl;
//}
//}
create_path(str);

md_spi_p = new class_md_spi(this);
//实例化行情api指针
str = path_str + "/md/";
md_api_p = CThostFtdcMdApi::CreateFtdcMdApi(str.c_str());
//注册行情事件类
md_api_p->RegisterSpi(md_spi_p);


for(auto& front: md_front_list)
{
md_api_p->RegisterFront(const_cast<char*>(front.c_str()));
}


//初始化工作
md_api_p->Init();
std::cout << "行情构造完成" << std::endl;

flag[0] = 1;

std::cout << "实例化交易对象" << std::endl;
//实例化 交易 spi
trader_spi_p = new class_trader_spi(this);
str = path_str + "/trader/";
//实例化交易api指针
trader_api_p = CThostFtdcTraderApi::CreateFtdcTraderApi(str.c_str());
//注册回调spi
trader_api_p->RegisterSpi(trader_spi_p);
//订阅私有刘
//trader_api_p->SubscribePrivateTopic(THOST_TERT_RESTART);
trader_api_p->SubscribePrivateTopic(THOST_TERT_RESUME);
//订阅工友流
trader_api_p->SubscribePublicTopic(THOST_TERT_RESTART);
//trader_api_p->SubscribePublicTopic(THOST_TERT_RESUME);


for(auto &front: trader_front_list)
{
trader_api_p->RegisterFront(const_cast<char*>(front.c_str()));
}


//初始化交易api
trader_api_p->Init();
//交易实现完毕
std::cout << "交易实例化完毕" << std::endl;

return 0;
}


// 报单
int class_center::bd(TThostFtdcInstrumentIDType dm, char dk, const char  kp[5], double price, int value,class_strategy_position &ccc)
{
CThostFtdcInputOrderField ord;//声明报单结构体
memset(&ord, 0, sizeof(CThostFtdcInputOrderField));
//经纪公司代码 
strncpy(ord.BrokerID, broker_str.c_str(), broker_str.size() );
//投资者代码 
strncpy(ord.InvestorID, user_str.c_str(), user_str.size() );
// 合约代码 
strncpy(ord.InstrumentID, dm, strlen(dm)+1);
///报单引用 
char my_orderref[13]={0};
snprintf(my_orderref, sizeof(my_orderref), "%012d", ++orderref);
strncpy(ord.OrderRef, my_orderref, sizeof(ord.OrderRef));
// 用户代码 
strncpy(ord.UserID, user_str.c_str(), user_str.size() );
// 报单价格条件 
ord.OrderPriceType = THOST_FTDC_OPT_LimitPrice;
// 买卖方向 
ord.Direction = dk;
// 组合开平标志 
strncpy(ord.CombOffsetFlag, kp, strlen(kp) + 1);
// 组合投机套保标志 
strcpy(ord.CombHedgeFlag, "1");
// 价格 
ord.LimitPrice = price;
// 数量 
ord.VolumeTotalOriginal = value;
// 有效期类型 
ord.TimeCondition = THOST_FTDC_TC_GFD;
// GTD日期 
strcpy(ord.GTDDate, "");
//交易所id
strncpy(ord.ExchangeID, hy_map[dm].ExchangeID, sizeof(ord.ExchangeID));
// 成交量类型 
ord.VolumeCondition = THOST_FTDC_VC_AV;
// 最小成交量 
ord.MinVolume = 0;
// 触发条件 
ord.ContingentCondition = THOST_FTDC_CC_Immediately;
// 止损价 
ord.StopPrice = 0;
// 强平原因 
ord.ForceCloseReason = THOST_FTDC_FCC_NotForceClose;
// 自动挂起标志 
ord.IsAutoSuspend = 0;

int my_nrequestid=++nrequestid;
int my_return = trader_api_p->ReqOrderInsert(&ord, my_nrequestid);
if(my_return == 0)
{
	ccc.insert(my_nrequestid,frontid,sessionid,my_orderref,atoi(tradingday.c_str()),dm);
}
return my_return;
}


//报单自动
int class_center::bd_auto(TThostFtdcInstrumentIDType dm, char dk, double price, int value, class_strategy_position& cc)
{
int  ll[2] = { 0 };

if (dk == '0')//如果是买入则
{
if (position_map.find(dm) != position_map.end())
{
ll[0] = position_map[dm].p23.Position - position_map[dm].p23.LongFrozen;
ll[1] = position_map[dm].p13.Position - position_map[dm].p13.LongFrozen;
}

if (ll[0] > 0 && value > 0)
{
if(std::min(value,ll[0]) > 0 && bd(dm, dk, "4", price, std::min(value,ll[0]),cc ) == 0)
{
//cc.insert(nrequestid, frontid, sessionid, orderref, atoi(tradingday.c_str()),dm);
}
}

if (value > ll[0] && value > 0)
{
if (std::min(value - ll[0],ll[1]) > 0 && bd(dm, dk, "3", price, std::min(value - ll[0],ll[1]),cc ) == 0)
{
//cc.insert(nrequestid, frontid, sessionid, orderref, atoi(tradingday.c_str()), dm);
}
}

if (value > ll[0] + ll[1] && value > 0)
{

if(trading_account.Available > (value - ll[0] - ll[1]) * price * hy_map[dm].VolumeMultiple * hy_map[dm].LongMarginRatio || hy_map[dm].ProductClass == '2' && trading_account.Available > (value - ll[0] - ll[1]) * price * hy_map[dm].VolumeMultiple * hy_map[hy_map[dm].UnderlyingInstrID].LongMarginRatio)
{
if (bd(dm, dk, "0", price, value - ll[0] - ll[1],cc) == 0)
{
//cc.insert(nrequestid, frontid, sessionid, orderref, atoi(tradingday.c_str()), dm);
}
}
else
{
	std::cout<<"资金不足 报单失败,合约代码:"<<dm<<",价格:"<<price<<std::endl;
if(flag[3] != 0)
{
	log.msg("\n" + user_str + "\n资金不足,报单失败");
}
	log.insert("log","资金不足，报单失败,合约代码:" + std::string(dm) + ",价格:" + std::to_string(price) );
}
}

}// 下面是空头
else {
if (position_map.find(dm) != position_map.end())
{
ll[0] = position_map[dm].p22.Position - position_map[dm].p22.ShortFrozen;
ll[1] = position_map[dm].p12.Position - position_map[dm].p12.ShortFrozen;
}

if (value > 0 && ll[0] > 0)
{
if (std::min(value, ll[0]) > 0 && bd(dm, dk, "4", price, std::min(value, ll[0]),cc) == 0)
{
//cc.insert(nrequestid, frontid, sessionid, orderref, atoi(tradingday.c_str()), dm);
}
}

if (value > ll[0] && value > 0)
{
if (std::min(value - ll[0], ll[1]) > 0 && bd(dm, dk, "3", price, std::min(value - ll[0], ll[1]),cc ) == 0)
{
//cc.insert(nrequestid, frontid, sessionid, orderref, atoi(tradingday.c_str()), dm);
}
}

if (value > ll[0] + ll[1] && value > 0)
{

if(trading_account.Available > (value - ll[0] - ll[1]) * price * hy_map[dm].VolumeMultiple * hy_map[dm].ShortMarginRatio || hy_map[dm].ProductClass == '2' && trading_account.Available > (value - ll[0] - ll[1]) * price * hy_map[dm].VolumeMultiple * hy_map[hy_map[dm].UnderlyingInstrID].LongMarginRatio)
{
if (bd(dm, dk, "0", price, value - ll[0] - ll[1],cc) == 0)
{
//cc.insert(nrequestid, frontid, sessionid, orderref, atoi(tradingday.c_str()), dm);
}
}
else
{
	std::cout<<"资金不足 报单失败,合约代码:"<<dm<<",价格:"<<price<<std::endl;
if(flag[3] != 0)
{
	log.msg("\n" + user_str + "\n资金不足，报单失败");
}
	log.insert("log","资金不足，报单失败,合约代码:" + std::string(dm) + ",价格:" + std::to_string(price) );
}
}
}
return 0;
}


//同步策略持仓
int class_center::position_sync(class_strategy_position& cc)
{

	std::string key,dm;

//开始处理成交
for (auto it = cc.return_vector.begin(); it != cc.return_vector.end(); )
{
//key = std::to_string(it->orderref) + "_" + std::to_string(it->sessionid) + "_" + std::to_string(it->frontid);
key = synthesize_key(it->frontid, it->sessionid, it->orderref);
	dm = it->name;

auto bit = position_map[dm].order_map.find(key);
if (bit != position_map[dm].order_map.end() && it->orderref != 0 && bit->second.VolumeTraded >= it->traded)
{
//处理成交的
if (bit->second.OrderStatus == '0')
{
//如果方向是买入
if (bit->second.Direction == '0')
{
cc.position += (bit->second.VolumeTraded - it->traded);

if(position_map[dm].trade_list.begin() != position_map[dm].trade_list.end())
{
cc.value -= ( position_map[dm].trade_list.rbegin()->Price * (bit->second.VolumeTraded - it->traded)) ;
}
else
{
cc.value -= (tick_map[dm].LastPrice * (bit->second.VolumeTraded - it->traded)) ;
}

it->traded = bit->second.VolumeTraded;
}
else {//否则那就是卖出了
cc.position -= (bit->second.VolumeTraded - it->traded);

if(position_map[dm].trade_list.begin() != position_map[dm].trade_list.end())
{
cc.value += ( position_map[dm].trade_list.rbegin()->Price * (bit->second.VolumeTraded - it->traded)) ;
}
else
{
cc.value += (tick_map[dm].LastPrice * (bit->second.VolumeTraded - it->traded) );
}

it->traded = bit->second.VolumeTraded;
}
//写入磁盘
cc.write();
std::cout << "成交处理的，"<<dm<<"现在仓位" << cc.position << "价值"<<cc.value<<std::endl;
} //成交处理结束了
}
//撤单或全部成交了
if (bit != position_map[dm].order_map.end() && (bit->second.OrderStatus == '5' || bit->second.VolumeTotal == 0) || it->tradingday != atoi(tradingday.c_str()) && tradingday.size() > 1)
{
it = cc.return_vector.erase(it);
//写磁盘
cc.write();
}
else 
{
it++;
}

}

return 0;
}



//清理策略返回值
int class_center::return_erase(class_strategy_position &cc)
{
for (auto it = cc.return_vector.begin(); it != cc.return_vector.end(); )
{
if (InputOrder_map.find(it->id) != InputOrder_map.end() || it->orderref == 0 || tradingday.size() > 0 && it->tradingday != atoi(tradingday.c_str()))
{
it = cc.return_vector.erase(it);
}
else {
it++;
}
}
return 0;
}


// 撤单
int class_center::cd(class_strategy_position &cc)
{
CThostFtdcInputOrderActionField CDJG;//定义撤单结构体
memset(&CDJG, 0, sizeof(CThostFtdcInputOrderActionField));

for (auto it = cc.return_vector.begin(); it != cc.return_vector.end(); ++it)
{
///经纪公司代码
strcpy(CDJG.BrokerID, broker_str.c_str());
///投资者代码
strcpy(CDJG.InvestorID, user_str.c_str());
///报单操作引用
CDJG.OrderActionRef = ++orderref;
///报单引用
strncpy(CDJG.OrderRef, it->orderref, sizeof(CDJG.OrderRef));
///前置编号
CDJG.FrontID = it->frontid;
///会话编号
CDJG.SessionID = it->sessionid;
std::string str;
//str = std::to_string(it->orderref) + "_" + std::to_string(it->sessionid) + "_" + std::to_string(it->frontid);
str = synthesize_key(it->frontid, it->sessionid, it->orderref);

strcpy(CDJG.ExchangeID, position_map[it->name].order_map[str].ExchangeID);
strcpy(CDJG.OrderSysID, position_map[it->name].order_map[str].OrderSysID);
///操作标志
CDJG.ActionFlag = THOST_FTDC_AF_Delete;
///用户代码
strcpy(CDJG.UserID, broker_str.c_str());

int fh = trader_api_p->ReqOrderAction(&CDJG, ++nrequestid);
log.insert("撤单", str + "返回值" + std::to_string(fh));
}
return 0;
}


//合成key
std::string class_center::synthesize_key(int frontid, int sessionid, char orderref[])
{
	std::string key = "";
key = key +	orderref + "_" + std::to_string(sessionid) + "_" + std::to_string(frontid);
return key;
}


//更新主力合约
int class_center::up_hot()
{
for(auto it=hot_map_vector.begin();it!=hot_map_vector.end();++it)
{
it->second.clear();
}
for(auto it=hy_map.begin();it!=hy_map.end();++it)
{
hot_map_vector[it->second.ProductID].push_back(tick_map[it->first]);
}
for(auto it=hot_map_vector.begin();it!=hot_map_vector.end();++it)
{
	std::sort(it->second.begin(),it->second.end(),[](CThostFtdcDepthMarketDataField &a,CThostFtdcDepthMarketDataField &b){return a.OpenInterest > b.OpenInterest;});
}
return 0;
}

